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
super().__init__ doesn't work in explicit protocol subclasses #572
A possible solution is to append a call to existing __init__ while overwriting (after the check for _is_protocol=True, where we unconditionally raise because protocols can't be instantiated). This way explicit non-protocol subclasses can use a protocol __init__ as a "default constructor". Default implementations are already supported for other protocol members, so it is natural to expect that __init__ is not different. See also python/mypy#3823
changed the title [-]super().__init__ is not called in explicit protocol subclasses[/-][+]super().__init__ doesn't work in explicit protocol subclasses[/+]on Jul 13, 2018
Hi, I've just come across this in our testing when updating from 3.10.0.b4 to 3.10.0.rc1.
There's been some change made to protocols for 3.10.0 that change runtime behaviour?
In my case, the protocol classes don't have an __init__(), so I didn't expect them to cause an error, and they didn't with 3.8 or 3.9.
I can't see what the change is in the 3.10 release notes, maybe the fix for runtime_checkable protocols with only attributes? (But we have methods, just no init().)
Activity
[-]super().__init__ is not called in explicit protocol subclasses[/-][+]super().__init__ doesn't work in explicit protocol subclasses[/+]grahamc commentedon May 18, 2020
I have run in to this problem with @adisbladis, and he came up with this workaround:
I accidentally commented this on #561 at first, my apologies.
Work around Protocol.__init__ behaviour
Work around Protocol.__init__ behaviour
Yobmod commentedon Aug 9, 2021
Hi, I've just come across this in our testing when updating from 3.10.0.b4 to 3.10.0.rc1.
There's been some change made to protocols for 3.10.0 that change runtime behaviour?
In my case, the protocol classes don't have an
__init__(), so I didn't expect them to cause an error, and they didn't with 3.8 or 3.9.I can't see what the change is in the 3.10 release notes, maybe the fix for runtime_checkable protocols with only attributes? (But we have methods, just no init().)
grahamc commentedon Aug 9, 2021
@Yobmod this bug has been open for 3 years, I wonder if you did some research that ties such a very recent change to this bug in particular?
hauntsaninja commentedon Aug 9, 2021
https://bugs.python.org/issue44806 / python/cpython#27545
Yobmod commentedon Aug 9, 2021
@hauntsaninja Thanks for the heads-up! (I put in a workaround for now, but I'll check if fixed next rc).
srittau commentedon Nov 4, 2021
Closing here as this has been filed to bpo.