-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
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
callable.__call__ leads to Callable is not callable #5079
Comments
I'm affected by this too! |
@ezyang, do you have some real world code that triggers this? |
Actually, it turns out my bug is unrelated (and I was trying to (incorrectly) use |
The error message on 0.941 is arguably even worse:
But it doesn't seem like there's much real-world code affected by this, so I'm lowering the priority level. |
any updates to this problem? |
I am experiencing this problem in this PR: fastapi/fastapi#5461 |
I have some real-world example: I am writing a lazy function class, that takes a Now, regular functions and callable classes store from types import FunctionType
from typing import Callable
def show_annotations(func: Callable) -> None:
if isinstance(func, FunctionType):
print(func.__annotations__)
else:
print(func.__call__.__annotations__) # ✘ error [operator]
class Foo:
def __call__(self) -> None:
pass
def foo() -> None:
pass
show_annotations(foo)
show_annotations(Foo()) |
@randolf-scholz note that your code isn't type-safe as there is no guarantee that the Obviously the mypy error at issue here is still a bug. |
This applies to any callable, as far as I can see. Here's a simple test case: gist def some_function() -> None:
pass
some_function.__call__
# error: "Callable[[], None]" not callable [operator] |
In a quite amusing, confusing error:
The text was updated successfully, but these errors were encountered: