-
Notifications
You must be signed in to change notification settings - Fork 0
function wrappers
pboisver edited this page Nov 12, 2024
·
2 revisions
import functools
def deprecated(message="This method is deprecated."):
def decorator(func):
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
print(f"Deprecation warning: {message}")
return func(self, *args, **kwargs)
return wrapper
return decorator
class MyClass:
@deprecated()
def old_method(self):
print("Using old method")
def new_method(self):
print("Using new method")
obj = MyClass()
obj.old_method() # Outputs: Deprecation warning: This method is deprecated.
obj.new_method()