Skip to content

Make sure all deprecations are properly removed #114

Open
@ferrine

Description

@ferrine

Description

Right now we've lost track of deprecated functions. See #111

import warnings
import functools

__version__ = "0.1.1"
def deprecate(*, start: str, removed: str):
    if __version__ >= removed:
        raise RuntimeError(f"After incrementing version {__version__} this function has to be removed")
    else:
        def wrapper(fn):
            @functools.wraps(fn)
            def wrapped_fn(*args, **kwargs):
                warnings.warn(f"This function is deprecated in version {start} and "
                              f"will be removed at version {removed}. Current version is {__version__}.", DeprecationWarning)
                return fn(*args, **kwargs)
            return wrapped_fn
        return wrapper

gives

@deprecate(start="0.0.1", removed="1.1.1")
def add(x, y):
    return x + y
add(1, 2)
/var/folders/rx/rk9gm4ln35z802s3p81wfz8r0000gp/T/ipykernel_10024/2831940282.py:9: DeprecationWarning: This function is deprecated in version 0.0.1 and will be removed at version 1.1.1. Current version is 0.1.1.
  warnings.warn(f"This function is deprecated in version {start} and "

And during increment version PR

@deprecate(start="0.0.1", removed="0.1.1")
def add(x, y):
    return x + y
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In [19], line 1
----> 1 @deprecate(start="0.0.1", removed="0.1.1")
      2 def add(x, y):
      3     return x + y

Cell In [16], line 4, in deprecate(start, removed)
      2 def deprecate(*, start: str, removed: str):
      3     if __version__ >= removed:
----> 4         raise RuntimeError(f"After incrementing version {__version__} this function has to be removed")
      5     else:
      6         def wrapper(fn):

RuntimeError: After incrementing version 0.1.1 this function has to be removed

For flexibility we can build similar thing on top of
https://borda.github.io/pyDeprecate/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions