You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
fromtypingimportProtocolclassA(Protocol):
__name__: strdef__call__(self) ->None: ...
deff() ->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__).
The text was updated successfully, but these errors were encountered:
Apologies again for creating a duplicate ; sorry for the noise as well, but I'm guessing some activity could help with searchability :-) thanks for all the great work!
Fixes#10976Fixes#10403
This is quite straightforward. Note that we will not allow _arbitrary_
attributes on functions, only those that are defined in
`types.FunctionType` (or more precisely `builtins.function` that is
identical). We have a separate issue for arbitrary attributes
#2087
User-defined functions come, among others, with the special attribute
__name__
. Mypy 0.812 correctly reveals the typestr
for attribute__name__
of functionf
in the following example. Still, it states an assignment error when trying to handlef
as a subtype of the callback protocolA
, which also defines a__name__
attribute of typestr
.This problem also occurs for all other special attributes I checked (e.g.
__doc__
).The text was updated successfully, but these errors were encountered: