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
{{ message }}
Repository navigation
hinting method decorators with protocols fails to remove the self attribute when binding #16200
When hinting a decorator used on methods using Callable, the unbound method and bound method types differ by the first/self parameter as I expect. When I replace the Callable with a Protocol providing .__call__() instead, the unbound and bound cases are the same.
I don't know the details around 'modifying' protocols such as would be required here but I would expect that unbound and bound would not be the same.
Actual Behavior
Unbound and bound methods decorated with a decorator hinted with protocols have the same type.
main.py:15: note: Revealed type is "def (__main__.C, builtins.int) -> builtins.str"
main.py:16: note: Revealed type is "def (builtins.int) -> builtins.str"
main.py:34: note: Revealed type is "__main__.P"
main.py:35: note: Revealed type is "__main__.P"
Success: no issues found in 1 source file
Your Environment
Mypy version used: 1.5.1, master
Mypy command-line flags: mypy-play defaults
Mypy configuration options from mypy.ini (and other config files): none
Thanks, I think #15993 makes this behave as you expect
Might need to see if a creative solution can be worked out for minimising some of the downstream impact
Activity
hauntsaninja commentedon Sep 30, 2023
Thanks, I think #15993 makes this behave as you expect
Might need to see if a creative solution can be worked out for minimising some of the downstream impact
RonnyPfannschmidt commentedon Jul 10, 2024
after some digging i realized,that self attribute removal is indeed incorrect
callables and methof descriptors are different things
unfortunately the "correct" version spells out like
RonnyPfannschmidt commentedon Jul 10, 2024
the working version spells like
i wish there was a builtin version of that