Skip to content

Commit af2c028

Browse files
committed
Avoid looking at local variables for deprecation warnings
1 parent f41581a commit af2c028

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

redisvl/utils/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
import json
23
from enum import Enum
34
from functools import wraps
@@ -76,7 +77,7 @@ def deprecated_argument(argument: str, replacement: Optional[str] = None) -> Cal
7677
def wrapper(func):
7778
@wraps(func)
7879
def inner(*args, **kwargs):
79-
argument_names = func.__code__.co_varnames
80+
argument_names = list(inspect.signature(func).parameters.keys())
8081

8182
if argument in argument_names:
8283
warn(message, DeprecationWarning, stacklevel=2)

tests/unit/test_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
import numpy as np
23
import pytest
34

@@ -237,3 +238,15 @@ async def test_func(dtype=None, vectorizer=None):
237238
with pytest.warns(DeprecationWarning):
238239
result = await test_func(dtype="float32")
239240
assert result == 1
241+
242+
async def test_ignores_local_variable(self):
243+
@deprecated_argument("dtype")
244+
async def test_func(vectorizer=None):
245+
# The presence of this variable should not trigger a warning
246+
dtype = "float32"
247+
return 1
248+
249+
# This will raise an error if any warning is emitted
250+
with warnings.catch_warnings():
251+
warnings.simplefilter("error")
252+
await test_func()

0 commit comments

Comments
 (0)