Skip to content

Commit 68f00ab

Browse files
mhmdkanjtaylorhakes
authored andcommitted
feat(cache): support caching functions with positional-only arguments
BREAKING CHANGE: requires Python version >= 3.8
1 parent 4287411 commit 68f00ab

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

redis_cache/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def get_args(fn, args, kwargs):
1414
them both the same. Otherwise there would be different caching for add(1, 2) and add(arg1=1, arg2=2)
1515
"""
1616
arg_sig = signature(fn)
17-
standard_args = [param.name for param in arg_sig.parameters.values() if param.kind is param.POSITIONAL_OR_KEYWORD]
17+
standard_args = [param.name for param in arg_sig.parameters.values() if param.kind is param.POSITIONAL_OR_KEYWORD or param.kind is param.POSITIONAL_ONLY]
1818
allowed_kwargs = {param.name for param in arg_sig.parameters.values() if param.kind is param.POSITIONAL_OR_KEYWORD or param.kind is param.KEYWORD_ONLY}
1919
variable_args = [param.name for param in arg_sig.parameters.values() if param.kind is param.VAR_POSITIONAL]
2020
variable_kwargs = [param.name for param in arg_sig.parameters.values() if param.kind is param.VAR_KEYWORD]

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
77
long_description = f.read()
88

9-
__version__ = "3.2.0"
9+
__version__ = "4.0.0"
1010

1111
setup(
1212
name='python-redis-cache',
@@ -17,7 +17,7 @@
1717
url='http://github.com/taylorhakes/python-redis-cache',
1818
author='Taylor Hakes',
1919
license='MIT',
20-
python_requires='>=3.6',
20+
python_requires='>=3.8',
2121
packages=find_packages(),
2222
install_requires=['redis'],
2323
setup_requires=['pytest-runner==5.3.1'],

tests/test_redis_cache.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,17 @@ def fn4(a, *c, d, **e):
362362
def fn5(*, d, **e):
363363
pass
364364

365+
def fn6(a, b, /, c, d):
366+
pass
367+
365368
assert get_args(fn1, (1,2), {}) == dict(a=1, b=2)
366369
assert get_args(fn1, [], dict(a=1, b=2)) == dict(a=1, b=2)
367370
assert get_args(fn1, [1], dict(b=2)) == dict(a=1, b=2)
368371
assert get_args(fn2, [1,2,3,4], {}) == dict(a=1, b=2, c=[3,4])
369372
assert get_args(fn3, [1, 2, 3, 4], {}) == dict(c=[1, 2, 3, 4])
370373
assert get_args(fn4, [1, 2, 3, 4], dict(d=5, f=6, g=7, h=8)) == dict(a=1, c=[2, 3, 4], d=5, e=dict(f=6, g=7, h=8))
371374
assert get_args(fn5, [], dict(d=5, f=6, g=7, h=8)) == dict(d=5, e=dict(f=6, g=7, h=8))
375+
assert get_args(fn6, [1, 2, 3], dict(d=4)) == dict(a=1, b=2, c=3, d=4)
372376

373377
# Simulate the environment where redis is not available
374378
# Only test the CacheDecorator since the exception handling should be done inside the decorator

0 commit comments

Comments
 (0)