Skip to content

Commit 8e0e7f4

Browse files
BordaCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 7a3fa38 commit 8e0e7f4

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/cachier/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,10 @@ def _cachier_decorator(func):
375375
f"@cachier cannot decorate instance method "
376376
f"'{func.__qualname__}' because the 'self' parameter is "
377377
f"excluded from cache-key computation and all instances "
378-
f"would share a single cache. Pass "
379-
f"allow_non_static_methods=True to the decorator (or "
380-
f"set_global_params) if cross-instance cache sharing is "
381-
f"intentional."
378+
f"would share a single cache. Pass allow_non_static_methods=True "
379+
f"to the decorator or call "
380+
f"set_global_params(allow_non_static_methods=True) if "
381+
f"cross-instance cache sharing is intentional."
382382
)
383383

384384
is_coroutine = inspect.iscoroutinefunction(func)

tests/test_smoke.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,10 @@ def func():
174174
def test_classmethod_not_guarded():
175175
"""Test that @classmethod (cls) does not trigger the instance method guard.
176176
177-
Note: The decorator order must be @classmethod first, then @cachier,
178-
so that cachier sees the underlying function (whose first param is
179-
``cls``, not ``self``) and the guard is not triggered.
177+
Note: Place ``@classmethod`` above ``@cachier`` so that ``@cachier``
178+
decorates the underlying function before it is wrapped as a classmethod.
179+
This way cachier sees ``cls`` (not ``self``) as the first parameter and
180+
the instance-method guard is not triggered.
180181
181182
"""
182183

@@ -204,15 +205,18 @@ def method(cls, x):
204205
@pytest.mark.smoke
205206
def test_instance_method_global_opt_out_reset():
206207
"""Test that resetting allow_non_static_methods=False re-enables the guard."""
207-
set_global_params(allow_non_static_methods=True)
208-
set_global_params(allow_non_static_methods=False)
209-
with pytest.raises(TypeError, match="instance method"):
210-
211-
class Foo:
212-
@cachier_decorator(backend="memory")
213-
def method(self, x):
214-
return x
215-
208+
original = get_global_params().allow_non_static_methods
209+
try:
210+
set_global_params(allow_non_static_methods=True)
211+
set_global_params(allow_non_static_methods=False)
212+
with pytest.raises(TypeError, match="instance method"):
213+
214+
class Foo:
215+
@cachier_decorator(backend="memory")
216+
def method(self, x):
217+
return x
218+
finally:
219+
set_global_params(allow_non_static_methods=original)
216220

217221
@pytest.mark.smoke
218222
def test_instance_method_skip_cache():

0 commit comments

Comments
 (0)