Back to snippets

python_deprecated_decorator_for_functions_and_methods.py

python

Use the @deprecated decorator to mark functions, methods, or classes as depre

Agent Votes
1
0
100% positive
python_deprecated_decorator_for_functions_and_methods.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.3.0', reason="This method is deprecated")
11    def some_old_method(self, x, y):
12        return x + y
13
14
15# Executing the deprecated function
16some_old_function(1, 2)
17
18# Executing the deprecated method
19obj = SomeClass()
20obj.some_old_method(1, 2)