Skip to content

Preserve positional-only parameters in curry signatures - #646

Open
FanWu-ai wants to merge 1 commit into
pytoolz:masterfrom
FanWu-ai:fix-curry-positional-only-signature
Open

FanWu-ai wants to merge 1 commit into
pytoolz:masterfrom
FanWu-ai:fix-curry-positional-only-signature

Conversation

@FanWu-ai

@FanWu-ai FanWu-ai commented Oct 8, 2026 •

Copy link
Copy Markdown

Problem

Keywords whose names coincide with positional-only parameters belong to **kwargs. curry.__signature__ currently treats those keywords as bindings for the positional-only parameters instead. This changes their defaults and kinds, converts later parameters to keyword-only, and can remove *args entirely.

For example:

import inspect
from toolz import curry

def f(a=1, /, *args, **kwargs):
    return a, args, kwargs

wrapped = curry(f, a=10)
wrapped(2, 3)  # (2, (3,), {'a': 10})
inspect.signature(wrapped).bind(2, 3)  # TypeError: too many positional arguments

The advertised signature is (*, a=10, **kwargs), while a remains positional-only with its original default and *args remains available.

Change

Exclude positional-only parameters from keyword-binding transformations in curry.__signature__. Add regression coverage for same-named keyword bindings, multiple positional-only parameters, preservation of variadic arguments, and a simultaneous real positional-or-keyword binding.

Validation

Python 3.12.14. Four new regression cases fail before the source fix and pass afterward. Final local checks:

  • coverage run -m pytest --doctest-modules toolz/: 272 passed, 2 expected skips (a skipped doctest and Python 3.14-only annotation test).

  • pytest bench/: 19 passed.

  • Repository-wide pycodestyle --ignore="E731,W503,W504,E402" --exclude=conf.py,tests,examples,bench -r --show-source .: passed.

  • git diff --check: passed.

  • pre-commit run --all-files: passed, including PySentry, actionlint, zizmor, and all remaining applicable hooks.

Additional validation completed after opening this draft:

  • python -m build and python -m twine check --strict dist/*: passed for baseline and final code, including wheel and sdist.
  • Sphinx HTML builds with warnings treated as errors: passed for baseline and final code.
  • Re-ran the full suite after installing build tools: 272 passed, 2 expected skips.

AI assistance disclosure: this fix, regression tests, and description were prepared with an OpenAI coding assistant.

@FanWu-ai
FanWu-ai marked this pull request as ready for review October 8, 2026 06:26

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant