-
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
Deprecated names? #44
Comments
Thank you for your question. Actually, you can already have a old function which is a deprecated version of a new function name, here is how you can do that: from deprecated import deprecated
def new_function():
pass
old_function = deprecated(reason=u"Use new_function() instead", version="2.3.0")(new_function)
if __name__ == '__main__':
old_function()
new_function() You'll have a warning message only if you use the old function: demo.py:12: DeprecationWarning: Call to deprecated function (or staticmethod) new_function. (Use new_function() instead) -- Deprecated since version 2.3.0.
old_function() For classes, it's another story because this is the I'll try to given you a workaround later. |
A workaround for classes could be designed as follow: the "old" class can be redefined and inherit the "new" class. Then you need to implement a from deprecated import deprecated
class NewClass(object):
pass
@deprecated(reason=u"Use NewClass instead", version="2.3.0")
class OldClass(NewClass):
@classmethod
def __new__(cls, *args, **kwargs):
return super(OldClass, cls).__new__(cls)
# or, if ``NewClass.__new__`` is defined:
# return super(OldClass, cls).__new__(cls, *args, **kwargs)
if __name__ == '__main__':
old_obj = OldClass()
new_obj = NewClass() You get: demo.py:19: DeprecationWarning: Call to deprecated class OldClass. (Use NewClass instead) -- Deprecated since version 2.3.0.
old_obj = OldClass() |
I will leave this issue opened until I implement module-level deprecation. |
Module-level depreciation is currently being developed. Stay tune. |
Adding these examples to the docs would be good too |
(Feature request)
I would like to see a way to move a class, function, or method from one name to another, deprecating the old name.
So you could say:
I would say that it should raise a warning on direct use (ideally when the code referring to it is compiled, but implementing that would be unacceptably magical).
The text was updated successfully, but these errors were encountered: