Skip to content

Initial release

Compare
Choose a tag to compare
@Borda Borda released this 20 Mar 08:42
· 79 commits to main since this release

Simple tooling for marking deprecated functions or classes and re-routing to the new successors' instance.

Overview

The common use-case is moving your functions across codebase or outsourcing some functionalities to new packages. For most of these cases, you want to hold some compatibility, so you cannot simply remove past function, and also for some time you want to warn users that functionality they have been using is moved and not it is deprecated in favor of another function (which shall be used instead) and soon it will be removed completely.

Another good aspect is to do not overwhelm a user with too many warnings, so per function/class, this warning is raised only N times in the preferable stream.

Installation

Simple installation from PyPI:

pip install pyDeprecate

Use-cases

The functionality is kept simple and all default shall be reasonable, but still, you can do extra customization such as:

  • define user warning message and preferable stream
  • extended argument mapping to target function/method

Simple function forwarding

It is very straight forward, you forward your function call to new function and all arguments are mapped:

def base_sum(a: int = 0, b: int = 3) -> int:
    """My new function anywhere in codebase or even other package."""
    return a + b

# ---------------------------

from deprecate import deprecated

@deprecated(target=base_sum, deprecated_in="0.1", remove_in="0.5")
def depr_sum(a: int, b: int = 5) -> int:
    """
    My deprecated function which now has empty body
     as all calls are routed to the new function.
    """
    pass  # or you can just place docstring as one above

# call this function will raise deprecation warning:
#   The `depr_sum` was deprecated since v0.1 in favor of `__main__.base_sum`.
#   It will be removed in v0.5.
print(depr_sum(1, 2))