-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Labels
bugmypy got something wrongmypy got something wrong
Description
Here's a minimized repro:
from collections.abc import Callable
async def f[T](g: Callable[[T], bool]) -> T | None:
return None
async def f2[T](g: Callable[[T], bool]) -> T | None:
return await f(g)
$ mypy bug.py
bug.py:7: error: Argument 1 to "f" has incompatible type "Callable[[T], bool]"; expected "Callable[[T | None], bool]" [arg-type]
Found 1 error in 1 file (checked 1 source file)
$ mypy --version
mypy 1.17.1 (compiled: yes)
$ python --version
Python 3.13.3
$ uname -v
Darwin Kernel Version 24.6.0: Mon Jul 14 11:28:30 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6030
An alternative type checker works fine with the above code:
$ pyright bug.py
0 errors, 0 warnings, 0 informations
$ pyright --version
pyright 1.1.404
Close variations seem to work fine:
No async
from collections.abc import Callable
def f[T](g: Callable[[T], bool]) -> T | None:
return None
def f2[T](g: Callable[[T], bool]) -> T | None:
return f(g)
$ mypy bug.py
Success: no issues found in 1 source file
No generic in callable argument
from collections.abc import Callable
async def f[T](g: Callable[[int], bool]) -> T | None:
return None
async def f2[T](g: Callable[[int], bool]) -> T | None:
return await f(g)
$ mypy bug.py
Success: no issues found in 1 source file
No optional return type
from collections.abc import Callable
async def f[T](g: Callable[[T], bool]) -> None:
return None
async def f2[T](g: Callable[[T], bool]) -> None:
return await f(g)
$ mypy bug.py
Success: no issues found in 1 source file
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong