Skip to content

gh-107831: Fix inspect.getcallargs accepting positional-only args by keyword#151900

Open
iamsharduld wants to merge 1 commit into
python:mainfrom
iamsharduld:local-gh-107831-getcallargs-posonly
Open

gh-107831: Fix inspect.getcallargs accepting positional-only args by keyword#151900
iamsharduld wants to merge 1 commit into
python:mainfrom
iamsharduld:local-gh-107831-getcallargs-posonly

Conversation

@iamsharduld

@iamsharduld iamsharduld commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

inspect.getcallargs() built its set of acceptable keyword names from
getfullargspec's args, which includes positional-only parameters, so a
positional-only parameter could be filled by keyword without error -- unlike an
actual call or Signature.bind():

>>> inspect.getcallargs(lambda a, /: None, a=1)
{'a': 1}          # should raise TypeError

Derive the positional-only names from the code object's co_posonlyargcount,
exclude them from keyword matching, and raise the same TypeError the
interpreter does. The behaviour was checked against real calls (exception type
and message) for functions, methods, and the case where **kwargs absorbs the
name.

…gs by keyword

getcallargs() built the set of acceptable keyword names from getfullargspec's
'args', which includes positional-only parameters, so a positional-only
parameter could be filled by keyword without error -- unlike an actual call
or Signature.bind(). Exclude positional-only names (derived from the code
object's co_posonlyargcount) from keyword matching and raise the same
TypeError the interpreter does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant