Skip to content

help() output of lambda with manually set __annotations__ is one char off #107155

Closed
@Dutcho

Description

@Dutcho

Bug report

help() output of lambda with manually set __annotations__ is slightly scrambled.

f = lambda a, b, c: 0              # lambdas cannot have annotations
f.__annotations__['return'] = int  # but you can set them manually

help(f)                            # superfluous ")" and missed last char
# <lambda> lambda a, b, c) -> in

import inspect
print(inspect.signature(f))        # correctly displays
# (a, b, c) -> int

Note

This is a minor glitch for an atypical (perhaps even unsupported) use of annotations.

Hypothesis

Perhaps help() uses (the same logic as) inspect.signature() and (to reflect lambda syntax) wants to drop the brackets "(...)", but then has a one-off error for its text slice (picking ") -> in" instead of " -> int")

Environment

  • CPython versions tested on: 3.6.8 - 3.11.4, 3.12.0b4
  • Operating system and architecture: Windows 11

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and security fixesstdlibPython 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