Skip to content

Commit

Permalink
Keep deprecation_warning decorator (for future)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmower committed Aug 11, 2023
1 parent 2fd51c2 commit cd44b3d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions optas/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""! @brief Several Model classes are defined."""
import os
import warnings
import functools
import pathlib

Expand Down Expand Up @@ -52,6 +53,29 @@ def listify(*args, **kwargs):
return listify


def deprecation_warning(name_to):
def decorator(function):
def wrapper(*args, **kwargs):
name_from = function.__name__
warn = f"'{name_from}' will be deprecated, please use '{name_to}' instead"
msg = "\033[93m" + warn + "\033[0m" # add
warnings.warn(msg, DeprecationWarning, stacklevel=2)
self_ = args[0]
new_function = getattr(self_, name_to)
while hasattr(new_function, "__wrapped__"):
new_function = new_function.__wrapped__

args_use = list(args)
if function.__name__.endswith("_function"):
args_use = args_use[1:]

return new_function(*args_use, **kwargs)

return wrapper

return decorator


class Model:
"""! The Model base class.
Defines the base class utilized by all models.
Expand Down

0 comments on commit cd44b3d

Please sign in to comment.