Skip to content

inspect.Signature documentation incorrect on "parameters" parameter #130818

@phemmer

Description

@phemmer

Bug report

Bug description:

The documentation states:

parameters
An ordered mapping of parameters’ names to the corresponding Parameter objects.

This is incorrect and it should actually be an iterable, as that is how the code treats it. If you pass it a mapping, the code will iterate over it, and only obtain the keys, and not the values.

import inspect

def foo(arg):
    ...

sig = inspect.signature(foo)

print(repr(sig.parameters))
sig.replace(parameters=sig.parameters)
mappingproxy(OrderedDict({'arg': <Parameter "arg">}))
Traceback (most recent call last):
  File "/tmp/test.py", line 9, in <module>
    sig.replace(parameters=sig.parameters)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/inspect.py", line 3094, in replace
    return type(self)(parameters,
           ~~~~~~~~~~^^^^^^^^^^^^
                      return_annotation=return_annotation)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/inspect.py", line 3029, in __init__
    kind = param.kind
           ^^^^^^^^^^
AttributeError: 'str' object has no attribute 'kind'. Did you mean: 'find'?

Tested on 3.13.2

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions