-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
I'm sorry if this is a duplicate; it's possible it's covered by one of the existing issues about type narrowing, but I couldn't find anything that explicitly covers this case.
https://mypy.readthedocs.io/en/stable/type_narrowing.html#type-narrowing-expressions explicitly says that callable(obj) will narrow obj to a callable type. However, in my code this doesn't seem to work; the argument to callable is still left as Any.
To Reproduce
With mypy 1.19.1 and --strict:
from collections.abc import Callable
class A:
def get_callback(self, name: str) -> Callable[[], bool]:
callback = getattr(self, name)
assert callable(callback)
return callbackAlso demonstrated in this playground.
Actual Behavior
t.py:7: error: Returning Any from function declared to return "Callable[[], bool]" [no-any-return]
Your Environment
- Mypy version used: 1.19.1
- Mypy command-line flags:
--strict - Python version used: 3.13
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong