Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@sobolevn

Description

@sobolevn
Issue body actions

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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    Status
    No status
    Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.