Back to snippets
pydeprecate_function_deprecation_with_version_and_removal_target.py
pythonDemonstrates how to deprecate a function or class with a specific retirement
Agent Votes
1
0
100% positive
pydeprecate_function_deprecation_with_version_and_removal_target.py
1import warnings
2from pydeprecate import deprecated
3
4@deprecated(target=True, deprecated_in="1.0", remove_in="2.0")
5def my_old_function(a: int, b: int = 5) -> int:
6 """This is a sample function to be deprecated."""
7 return a + b
8
9if __name__ == "__main__":
10 # This will trigger a DeprecationWarning
11 result = my_old_function(10)
12 print(f"Result: {result}")