Skip to content

inspect.get_source(lambda) improvement #136521

Open
@dg-pb

Description

@dg-pb

Feature or enhancement

Proposal:

l1, v1, v2 = (lambda x: x), 1, 2
print(inspect.getsource(l1)[:-1])
# l1, v1, v2 = (lambda x: x), 1, 2

As the request is for the source of lambda, it might be convenient to extract only the lambda substring, not the whole line.

l1, l2 = (lambda x: x), (lambda x: (x[0] + 1) / 2)
print(inspect.getsource(l1)[:-1])
# l1, l2 = (lambda x: x), (lambda x: (x[0] + 1) / 2)

It might also be nicer to extract the substring of lambda that was requested in case of more than 1 lambda?

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions