Skip to content

Make sure all deprecations are properly removed #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ferrine opened this issue Dec 13, 2022 · 0 comments
Open

Make sure all deprecations are properly removed #114

ferrine opened this issue Dec 13, 2022 · 0 comments

Comments

@ferrine
Copy link
Member

ferrine commented Dec 13, 2022

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant