Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repeated partial applications of builtins such as
curry(map)(func)andcurry(filter)(func)are slow on Python versions whereinspect.signaturecannot inspect those builtins.currystores the failed lookup asNone, which also means "not checked yet". The argument-check helpers then try introspection again before falling back to the builtin-signature registry.Cache a traceback-free
ValueErrororTypeErrorinstance instead. The existing argument-check helper already understands those results, so subsequent calls use the same fallback without repeating signature inspection. Keep the distinction between unavailable signatures (ValueError) and invalid signatures (TypeError), and avoid retaining exception traceback frames.Addresses #583. Two new regression cases exercise repeated calls through objects with unavailable or invalid signatures. Both fail before the fix (15 signature lookups rather than 1), then pass while preserving partial application, successful full calls, and TypeError propagation.
Measured on Windows / CPython 3.12.14, reusing one curried wrapper and evaluating
list(wrapped(identity)([1, 2, 3])); each timing is the median of five runs of 10,000 operations:inspect.signaturecalls per 100 warmed operationsmapfilterCPython 3.14 already exposes signatures for these builtins; its timings stay approximately unchanged (map 0.058/0.057 s, filter 0.075/0.075 s).
Validation:
coverage run -m pytest --doctest-modules toolz/: 270 passed, 2 expected skips.pytest bench/: 19 passed on each interpreter, using the original Gutenberg Shakespeare fixture. Used UTF-8 mode for this text fixture on Windows.pycodestyle --ignore="E731,W503,W504,E402"check andgit diff --checkpassed.Other operating systems and the remaining interpreter matrix were not run locally.