Borda / pyDeprecate

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

Home Page:https://borda.github.io/pyDeprecate/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kwargs it's not supportd

jungbaepark opened this issue Β· comments

πŸ› Bug

If the target function has kwargs and contains kwargs.get, the deprecated function will not be worked and cause Type Error.

To Reproduce

Steps to reproduce the behavior:

  1. Go to 'test" & add kwargs
class NewCls:

    def __init__(self, c: float, d: str = "abc", **kwargs):
        self.my_c = c
        self.my_d = d
        self.my_e = kwargs.get("e", 0.2)

& change test code of tests.test_classes

class PastCls(NewCls):

    @deprecated(target=NewCls, deprecated_in="0.2", remove_in="0.4")
    def __init__(self, c: int, d: str = "efg", **kwargs):
        pass



def test_deprecated_class_forward() -> None:
    with pytest.deprecated_call(
        match='The `PastCls` was deprecated since v0.2 in favor of `tests.collection_targets.NewCls`.'
        ' It will be removed in v0.4.'
    ):
        past = PastCls(2, e=0.1)
    assert past.my_c == 2
    assert past.my_d == "efg"
    assert past.my_e == 0.1
    assert isinstance(past, NewCls)
    assert isinstance(past, PastCls)

    # check that the warning is raised only once per function
    with no_warning_call():
        assert PastCls(c=2, d="", e=0.9999)

    PastCls.__init__._warned = False
    with pytest.deprecated_call(match='It will be removed in v0.4.'):
        PastCls(2)
  1. Run 'test codes.
  2. Scroll down to 'Type Error'
  3. See error

Hi! thanks for your contribution!, great first issue!