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
warnings.deprecated leads to incorrectly set _is_protocol on subclasses #138010
This seems to happen because the __init_subclass__ method that @deprecated adds directly calls the __init_subclass__ method of the class being decorated. The problem is that that doesn't consider other __init_subclass__ methods that may appear between the decorated class and its parents in the MRO of subclasses. In this case, DeprecatedBase.__init_subclass__ directly calls object.__init_subclass__, which means that Protocol.__init_subclass__ gets skipped when defining FooWithDeprecatedBase.
Here's a reproducer that doesn't involve Protocol:
I see, we need to distinguish between the case where __init_subclass__ is present directly on the decorated base (in which case we call it directly) and the case where it isn't (in which case we need to use super).
Just want to know if the if "__init_subclass__" in arg.__dict__: really necessary as we are already checking if the __init_subclass__ is a bound method of the decorated base if isinstance(original_init_subclass, MethodType):
Activity
brianschubert commentedon Aug 21, 2025
This seems to happen because the
__init_subclass__method that@deprecatedadds directly calls the__init_subclass__method of the class being decorated. The problem is that that doesn't consider other__init_subclass__methods that may appear between the decorated class and its parents in the MRO of subclasses. In this case,DeprecatedBase.__init_subclass__directly callsobject.__init_subclass__, which means thatProtocol.__init_subclass__gets skipped when definingFooWithDeprecatedBase.Here's a reproducer that doesn't involve
Protocol:cc @JelleZijlstra
JelleZijlstra commentedon Aug 21, 2025
I see, we need to distinguish between the case where
__init_subclass__is present directly on the decorated base (in which case we call it directly) and the case where it isn't (in which case we need to usesuper).XChaitanyaX commentedon Aug 28, 2025
Just want to know if the
if "__init_subclass__" in arg.__dict__:really necessary as we are already checking if the__init_subclass__is a bound method of the decorated baseif isinstance(original_init_subclass, MethodType):gh-138010: Fix `__init_subclass__` forwarding by `warnings.deprecated` (
pythongh-138010: Fix `__init_subclass__` forwarding by `warnings.depr…
[3.13] pythongh-138010: Fix `__init_subclass__` forwarding by `warnin…
[3.13] gh-138010: Fix `__init_subclass__` forwarding by `warnings.dep…
pythongh-138010: Fix `__init_subclass__` forwarding by `warnings.depr…
[3.14] gh-138010: Fix `__init_subclass__` forwarding by `warnings.dep…
frenzymadness commentedon Oct 8, 2025
The fix is implemented and merged. It seems this can be closed.