Skip to content

__annotate__ functions generated by CPython for class methods have an incorrect __qualname__ #137814

@DavidCEllis

Description

@DavidCEllis

Bug report

Bug description:

The __qualname__ of __annotate__ functions of methods of classes incorrectly refers to the __annotate__ function of the class itself.

class Example:
    x: int
    def func(self, x: int) -> str: ...

print(f"{Example.__annotate__.__qualname__ = }")
print(f"{Example.func.__annotate__.__qualname__ = }")

Output:

Example.__annotate__.__qualname__ = 'Example.__annotate__'
Example.func.__annotate__.__qualname__ = 'Example.__annotate__'

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-typingtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions