Skip to content

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

@sobolevn

Description

@sobolevn

Here's an example:

>>>fr=None>>>defa(p, /, a, *, b): ... globalfr ... fr=inspect.currentframe() ... >>>a(1, 2, b=3) >>>fr<frameat0x101275570, file'<stdin>', line3, codea>>>>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

@classmethoddeffrom_frame(cls, frame): ...

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions