pymc-devs / pymc-devs/pytensor

Make sure all deprecations are properly removed

Open
#114 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
644
Forks
208
Avg merge
2d 14h
Merged PRs (30d)
16

Description

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/

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the deprecation discussion in #111 and the proposed Python decorator behavior shown in this issue. Compare the desired version-checking workflow with pyDeprecate. Done should mean deprecated functions are tracked and removed appropriately during version increments, but the issue does not identify files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.