-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deprecate abstract method #72
Comments
To elaborate: the use-case is quite simple: I have a library with an abstract method, which gets deprecated at some point. Inheriting code (not under my control) should see the deprecation warning when their implemented method gets called. As a workaround, of course I can place the following in the superclass' constructor: class Parent:
def __init__(self, ...)
...
setattr(self, 'fun', deprecated(reason='try not to laugh')(getattr(self, 'fun'))) But of course it would be much nicer if |
You're correct; the previous solution won't work here. When a subclass overrides an abstract method, it completely replaces it, so the decorated parent method (with the deprecation warning) is never actually called. The decorator only issues a warning if the decorated method itself is called, which doesn’t happen with overridden abstract methods. Possible Approach: Introspection with To emit a warning when calling the overridden method in the subclass, one option is to add introspection logic to the decorator. This would involve checking the class's Method Resolution Order ( This approach introduces extra processing time, as each method call would require scanning the Currently, there isn’t a straightforward way to make deprecated warnings propagate to overridden abstract methods in subclasses, as the subclass method bypasses the parent method entirely. An introspective approach could work but would add significant overhead. |
This is a feature request (I think): I would like
deprecated
to be able to yield warnings on a method call, even when overriding the implementation in a subclass. In particular, I would like to be able to deprecate abstract methods.Expected Behavior
Running…
…I would like to see…
Actual Behavior
However, since the method is overriden, I can see no warning:
Environment
The text was updated successfully, but these errors were encountered: