Skip to content

inspect.getargvalues does not work correctly for pos-only and kw-only arguments #107833

Open
@sobolevn

Description

@sobolevn

Here's an example:

>>> fr = None
>>> def a(p, /, a, *, b): 
...     global fr
...     fr = inspect.currentframe()
... 
>>> a(1, 2, b=3)
>>> fr
<frame at 0x101275570, file '<stdin>', line 3, code a>
>>> inspect.getargvalues(fr)
ArgInfo(args=['p', 'a', 'b'], varargs=None, keywords=None, locals={'p': 1, 'a': 2, 'b': 3})

Right now inspect.getargvalues treats p, a, and b the same way. It is not very useful. How caller can do anything with these arguments if they all have different semantics? p must always be possitional, a can be both, b can only be keyword argument.

I propose adding inspect.signature support for frame objects and use it.
For example, adding to Signature class

@classmethod
def from_frame(cls, frame): ...

will provide a new API to do the same thing, but correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions