Skip to content

Commit df1089c

Browse files
committed
support classmethods
1 parent 2df93a6 commit df1089c

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

redisvl/utils/utils.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,13 @@ def decorator(func):
9393

9494
@wraps(underlying)
9595
def inner_wrapped(*args, **kwargs):
96-
sig = inspect.signature(underlying)
97-
bound_args = sig.bind(*args, **kwargs)
98-
if argument in bound_args.arguments:
96+
if argument in kwargs:
9997
warn(message, DeprecationWarning, stacklevel=2)
98+
else:
99+
sig = inspect.signature(underlying)
100+
bound_args = sig.bind(*args, **kwargs)
101+
if argument in bound_args.arguments:
102+
warn(message, DeprecationWarning, stacklevel=2)
100103
return underlying(*args, **kwargs)
101104

102105
if isinstance(func, classmethod):
@@ -107,10 +110,13 @@ def inner_wrapped(*args, **kwargs):
107110

108111
@wraps(func)
109112
def inner_normal(*args, **kwargs):
110-
sig = inspect.signature(func)
111-
bound_args = sig.bind(*args, **kwargs)
112-
if argument in bound_args.arguments:
113+
if argument in kwargs:
113114
warn(message, DeprecationWarning, stacklevel=2)
115+
else:
116+
sig = inspect.signature(func)
117+
bound_args = sig.bind(*args, **kwargs)
118+
if argument in bound_args.arguments:
119+
warn(message, DeprecationWarning, stacklevel=2)
114120
return func(*args, **kwargs)
115121

116122
return inner_normal

tests/unit/test_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,18 @@ def __init__(self, old_arg=None, new_arg=None):
382382
with assert_no_warnings():
383383
TestClass(new_arg="float32")
384384

385+
def test_class_init_keyword_argument_kwargs(self):
386+
class TestClass:
387+
@deprecated_argument("old_arg", "new_arg")
388+
def __init__(self, new_arg=None, **kwargs):
389+
pass
390+
391+
with pytest.warns(DeprecationWarning):
392+
TestClass(old_arg="float32")
393+
394+
with assert_no_warnings():
395+
TestClass(new_arg="float32")
396+
385397
async def test_async_function_argument(self):
386398
@deprecated_argument("old_arg", "new_arg")
387399
async def test_func(old_arg=None, new_arg=None):

0 commit comments

Comments
 (0)