Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fixes for Python 3.13 #206

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cytoolz/functoolz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ __all__ = ['identity', 'thread_first', 'thread_last', 'memoize', 'compose', 'com


cpdef object identity(object x):
""" Identity function. Return x

>>> identity(3)
3
"""
return x


Expand Down
6 changes: 4 additions & 2 deletions cytoolz/tests/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ def test_docstrings_uptodate():
d = merge_with(identity, toolz_dict, cytoolz_dict)
for key, (toolz_func, cytoolz_func) in d.items():
# only check if the new doctstring *contains* the expected docstring
toolz_doc = convertdoc(toolz_func)
cytoolz_doc = cytoolz_func.__doc__
# in Python < 3.13 the second line is indented, in 3.13+
# it is not, strip all lines to fudge it
toolz_doc = "\n".join((line.strip() for line in convertdoc(toolz_func).splitlines()))
cytoolz_doc = "\n".join((line.strip() for line in cytoolz_func.__doc__.splitlines()))
if toolz_doc not in cytoolz_doc:
diff = list(differ.compare(toolz_doc.splitlines(),
cytoolz_doc.splitlines()))
Expand Down
7 changes: 5 additions & 2 deletions cytoolz/tests/test_functoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,10 +748,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
24 changes: 21 additions & 3 deletions cytoolz/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 cytoolz
from cytoolz.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,23 @@ 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)),)
assert num_required_args(Wrapped) == 1
# 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
else:
assert num_required_args(Wrapped) is 1
Loading