-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug report
Mypy is not consistent between sync and async variants of the same code.
How to reproduce
Consider the following code:
from typing import Generic, TypeVar
T = TypeVar("T")
class Cls(Generic[T]):
pass
def create_cls(arg: T) -> Cls[tuple[T]]:
return Cls()
def inner(var: Cls[tuple[T]]) -> T | None:
return None
def outer(x: int) -> int | None:
c = create_cls(x)
return inner(c)Running mypy test.py yields no errors, as expected.
However, if we make the functions async:
from typing import Generic, TypeVar
T = TypeVar("T")
class Cls(Generic[T]):
pass
def create_cls(arg: T) -> Cls[tuple[T]]:
return Cls()
async def inner(var: Cls[tuple[T]]) -> T | None:
return None
async def outer(x: int) -> int | None:
c = create_cls(x)
return await inner(c)Then running mypy test.py gives:
test.py:21: error: Argument 1 to "inner" has incompatible type "Cls[tuple[int]]"; expected "Cls[tuple[int | None]]" [arg-type]
Found 1 error in 1 file (checked 1 source file)Expected Behavior
Mypy should give no errors in the async case, there's no difference in any of the function signatures.
Your Environment
- Mypy version used:
mypy 1.5.0 (compiled: yes) - Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.11.0rc1
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong