Skip to content

Commit 832e81d

Browse files
committed
test_inspect_wrapped_property: handle fixed wrapper inspection
Python upstream recently fixed the behavior of inspect with wrappers: python/cpython#112006 . The assertion here relies on the broken behavior, we only get None if `inspect(Wrapped)` fails and raises `ValueError`. Now it works, we actually get the correct answer, 1. This changes it so we assert the correct thing depending on the Python version (the fix was backported to 3.11.9 and 3.12.3, so the check has to be a bit complicated). Signed-off-by: Adam Williamson <[email protected]>
1 parent b79a954 commit 832e81d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

toolz/tests/test_inspect_args.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import inspect
33
import itertools
44
import operator
5+
import sys
56
import toolz
67
from toolz.functoolz import (curry, is_valid_args, is_partial_args, is_arity,
78
num_required_args, has_varargs, has_keywords)
@@ -482,6 +483,22 @@ def __wrapped__(self):
482483
wrapped = Wrapped(func)
483484
assert inspect.signature(func) == inspect.signature(wrapped)
484485

485-
assert num_required_args(Wrapped) is None
486-
_sigs.signatures[Wrapped] = (_sigs.expand_sig((0, lambda func: None)),)
486+
# inspect.signature did not used to work properly on wrappers,
487+
# but it was fixed in Python 3.11.9, Python 3.12.3 and Python
488+
# 3.13+
489+
inspectbroken = True
490+
if sys.version_info.major > 3:
491+
inspectbroken = False
492+
if sys.version_info.major == 3:
493+
if sys.version_info.minor == 11 and sys.version_info.micro > 8:
494+
inspectbroken = False
495+
if sys.version_info.minor == 12 and sys.version_info.micro > 2:
496+
inspectbroken = False
497+
if sys.version_info.minor > 12:
498+
inspectbroken = False
499+
500+
if inspectbroken:
501+
assert num_required_args(Wrapped) is None
502+
_sigs.signatures[Wrapped] = (_sigs.expand_sig((0, lambda func: None)),)
503+
487504
assert num_required_args(Wrapped) == 1

0 commit comments

Comments
 (0)