Bug Report
Since the new release, one of the projects that I use mypy is failing for the type Coroutine.
The code is like this:
fromtypingimportCoroutine,
defcompare_step_coroutines(
coro1: Optional[Coroutine], coro2: Optional[Coroutine]
) ->bool:
"""Compare two coroutines. :param coro1: coroutine to compare :type coro1: Optional[coroutine] :param coro2: coroutine to compare :type coro2: Optional[coroutine] :return: True if coroutines are equal :rtype: bool """ifcoro1isNoneorcoro2isNone:
# compare two None or one None and one Coroutinereturncoro1==coro2return (
# check if same coroutine was usedcoro1.cr_code==coro2.cr_code# check coroutine argumentsandinspect.getcoroutinelocals(coro1) ==inspect.getcoroutinelocals(coro2)
)
lint: commands[2]> mypy --install-types --non-interactive .
cou/steps/__init__.py:48: error: "Coroutine[Any, Any, Any]" has no attribute "cr_code" [attr-defined]
With this new release Coroutine doesn't recognize cr_code as a valid property.
I've tried to change to use types.CoroutineType and fixed for this issue, but errors started showing on other parts of the code. mypy still consider as Coroutine. E.g:
classFoodef__init__(self, coro: Optional[types.CoroutineType] =None):
self._coro: Optional[[types.CoroutineType] =corofoo=Foo(coro=my_coro_func)
asyncdefmy_coro_func():
returnNone
Argument "coro" to "Foo" has incompatible type "Coroutine[Any, Any, None]"; expected "CoroutineType[Any, Any, Any] | None" [arg-type] note: Maybe you forgot to use "await"?
Basically Coroutine cannot be used anymore like before and I don't see a possible workaround without ignoring the line that is complaining or pinning mypy to use a version < 1.15.0
Your Environment
- Mypy version used: 1.15.0
- Mypy command-line flags:
mypy --install-types --non-interactive . - Mypy configuration options from
mypy.ini (and other config files):
warn_unused_ignores = true
warn_unused_configs = true
warn_unreachable = true
disallow_untyped_defs = true
ignore_missing_imports = true
exclude = [
".eggs",
".git",
".tox",
".venv",
".build",
"build",
"lib",
"report",
"tests",
"docs"
]
Bug Report
Since the new release, one of the projects that I use mypy is failing for the type Coroutine.
The code is like this:
With this new release Coroutine doesn't recognize cr_code as a valid property.
I've tried to change to use
types.CoroutineTypeand fixed for this issue, but errors started showing on other parts of the code. mypy still consider asCoroutine. E.g:Basically
Coroutinecannot be used anymore like before and I don't see a possible workaround without ignoring the line that is complaining or pinning mypy to use a version <1.15.0Your Environment
mypy --install-types --non-interactive .mypy.ini(and other config files):