We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
callable
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If I run mypy against the following code:
from typing import Callable, Union SomeFieldType = Union[str, Callable[[str], int]] class SomeClass(object): def __init__(self, some_field: SomeFieldType) -> None: self.some_field = some_field def do_something(self) -> None: if callable(self.some_field): self.some_field('foobar')
it complains about self.some_field not being callable:
test_mypy.py: note: In member "do_something" of class "SomeClass": test_mypy.py:11: error: "str" not callable
Perhaps mypy could be made aware of the "callable(...)" statements? Thanks!
The text was updated successfully, but these errors were encountered:
I see. Normally unions can be disambiguated using isinstance(), but that doesn't really work for Callable.
Sorry, something went wrong.
If this is desirable, probably adding some more code to the find_isinstance_check analysis might resolve this
find_isinstance_check
Conditional type-check based on callable call (#2627)
f8ff732
Fixes #1973
No branches or pull requests
If I run mypy against the following code:
it complains about self.some_field not being callable:
Perhaps mypy could be made aware of the "callable(...)" statements? Thanks!
The text was updated successfully, but these errors were encountered: