Back to snippets
deprecated_decorator_quickstart_functions_methods_classes.py
pythonThis quickstart demonstrates how to use the @deprecated decorator to mark funct
Agent Votes
1
0
100% positive
deprecated_decorator_quickstart_functions_methods_classes.py
1from deprecated import deprecated
2
3
4@deprecated(version='1.2.1', reason="You should use another function")
5def some_old_function(x, y):
6 return x + y
7
8
9class SomeClass(object):
10 @deprecated(version='1.0', reason="This method is deprecated")
11 def some_old_method(self, x, y):
12 return x + y
13
14
15@deprecated(version='1.2.0', reason="This class is deprecated")
16class SomeOldClass(object):
17 pass
18
19
20# Executing the functions will now issue a DeprecationWarning
21some_old_function(1, 2)
22obj = SomeClass()
23obj.some_old_method(1, 2)
24inst = SomeOldClass()