-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
User-defined functions come, among others, with the special attribute __name__
. Mypy 0.812 correctly reveals the type str
for attribute __name__
of function f
in the following example. Still, it states an assignment error when trying to handle f
as a subtype of the callback protocol A
, which also defines a __name__
attribute of type str
.
from typing import Protocol
class A(Protocol):
__name__: str
def __call__(self) -> None: ...
def f() -> None: ...
reveal_type(f.__name__) # note: Revealed type is 'builtins.str'
a: A = f # error: Incompatible types in assignment (expression has type "Callable[[], None]", variable has type "A") [assignment]
This problem also occurs for all other special attributes I checked (e.g. __doc__
).
EvanKrall, povilasb, PeterJCLaw, harahu, treiher and 3 more