Skip to content

Call positional-only parameters positionally, by name (#14) - #33

Merged
thorwhalen merged 3 commits into
masterfrom
fix/14-positional-only
Oct 13, 2026
Merged

thorwhalen merged 3 commits into
masterfrom
fix/14-positional-only

Conversation

@thorwhalen

@thorwhalen thorwhalen commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Fixes #14. Also resolves the root cause of #13 (same attr(**kwargs) call), but #13 reports a gunicorn worker timeout I did not reproduce, so I leave #13 open with a comment.

py2http.util.call_with_inputs(func, args, kwargs) calls func(*args, **kwargs), but passes entries of kwargs that name positional-only parameters positionally (in declared order). A missing required one raises InputError (400) instead of a TypeError (500). A callable with no readable signature is called exactly as before. It is used by _get_attr_value (object/module/class dispatch: dict.__getitem__, __setitem__) and by the two plain-function handlers (def f(x, /)). The protocol from the issue works as written: {"_attr_name": "__getitem__", "key": "some_key"}.

Tests: py2http/tests/test_positional_only.py (unit, plus end-to-end WSGI for a dict endpoint and a plain function); suite 120 pass (109 before).

Adversarial review (fresh Opus subagent): requested changes; confirmed and fixed in the second commit, each with a test:

  1. Regression: a function with **kwargs and an optional positional-only parameter (Counter.update(iterable=None, /, **kwds), UserDict.update) used to receive a same-named JSON key as a keyword; it was now rebound positionally ({"_attr_name":"update","other":1} gave 500 instead of 200). Now, with **kwargs in the signature, only required positional-only parameters are bound by name.
  2. Class endpoints built objects with cls(**kwargs); they now go through call_with_inputs too.
    Not changed: inspect.signature runs per request (about 15 to 115 microseconds), minor next to HTTP overhead. No new exposure: the attribute policy is untouched.

🤖 Generated with Claude Code

thorwhalen and others added 3 commits October 13, 2026 06:16
…#14, #13)

call_with_inputs binds JSON keys that name positional-only parameters of the target (dict.__getitem__, __setitem__, def f(x, /)) and passes them positionally; a missing required one is an InputError (400). Used by attribute dispatch and by plain-function handlers.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…mes; constructors too

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…'t read their signature

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@thorwhalen
thorwhalen merged commit 3866d3a into master Oct 13, 2026
6 checks passed
@thorwhalen
thorwhalen deleted the fix/14-positional-only branch October 13, 2026 06:22
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.

Handling position-only arguments

1 participant