Skip to content

Commit

Permalink
Test fixes for changes in recent upstream Python (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWill committed Sep 27, 2024
1 parent 7a0382e commit 0c2b43a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 5 additions & 2 deletions toolz/tests/test_functoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,13 @@ def f(a, b):
def test_excepts():
# These are descriptors, make sure this works correctly.
assert excepts.__name__ == 'excepts'
# in Python < 3.13 the second line is indented, in 3.13+
# it is not, strip all lines to fudge it
testlines = "\n".join((line.strip() for line in excepts.__doc__.splitlines()))
assert (
'A wrapper around a function to catch exceptions and\n'
' dispatch to a handler.\n'
) in excepts.__doc__
'dispatch to a handler.\n'
) in testlines

def idx(a):
"""idx docstring
Expand Down
21 changes: 19 additions & 2 deletions toolz/tests/test_inspect_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import inspect
import itertools
import operator
import sys
import toolz
from toolz.functoolz import (curry, is_valid_args, is_partial_args, is_arity,
num_required_args, has_varargs, has_keywords)
Expand Down Expand Up @@ -482,6 +483,22 @@ def __wrapped__(self):
wrapped = Wrapped(func)
assert inspect.signature(func) == inspect.signature(wrapped)

assert num_required_args(Wrapped) is None
_sigs.signatures[Wrapped] = (_sigs.expand_sig((0, lambda func: None)),)
# inspect.signature did not used to work properly on wrappers,
# but it was fixed in Python 3.11.9, Python 3.12.3 and Python
# 3.13+
inspectbroken = True
if sys.version_info.major > 3:
inspectbroken = False
if sys.version_info.major == 3:
if sys.version_info.minor == 11 and sys.version_info.micro > 8:
inspectbroken = False
if sys.version_info.minor == 12 and sys.version_info.micro > 2:
inspectbroken = False
if sys.version_info.minor > 12:
inspectbroken = False

if inspectbroken:
assert num_required_args(Wrapped) is None
_sigs.signatures[Wrapped] = (_sigs.expand_sig((0, lambda func: None)),)

assert num_required_args(Wrapped) == 1

0 comments on commit 0c2b43a

Please sign in to comment.