You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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
Activity
Pin mypy to not block lint.
A5rocks commentedon Feb 7, 2025
This is intentional. You can have coroutines without
cr_code. This works:Comment I left on typeshed for more information: python/typeshed#10816 (comment)
A5rocks commentedon Feb 7, 2025
Note of course that the more correct thing to check is
isinstance(coro, types.CoroutineType):Pin mypy to not block lint.
Pin mypy to not block lint.
Pin mypy to not block lint. (#609)
Pin mypy to not block lint. (canonical#609)