Skip to content

PEP 749 / 3.14 regression: Method annotation incorrectly resolves to method itself when method name matches imported type #143306

@cjw296

Description

@cjw296

Bug report

Bug description:

When a method name is the same as an imported type used in its return type annotation, Python 3.14's PEP 749 annotation resolution incorrectly resolves the annotation to the method itself instead of the imported type.

This is a regression from Python 3.13 and breaks tools like Sphinx that introspect annotations.

Expected Behavior (Python 3.13)

from datetime import date

class Example:
    def date(self) -> date:
        return date(2025, 1, 1)

import inspect
print(inspect.signature(Example.date).return_annotation)
# <class 'datetime.date'>

Actual Behavior (Python 3.14)

from datetime import date

class Example:
    def date(self) -> date:
        return date(2025, 1, 1)

import inspect
print(inspect.signature(Example.date).return_annotation)
# <function Example.date at 0x...>

Reproducer

See attached py314_annotation_bug.py.

$ uv run --python 3.13 py314_annotation_bug.py 
Using CPython 3.13.7
Removed virtual environment at: .venv
Creating virtual environment at: .venv
Installed 14 packages in 13ms
Python version: 3.13.7 (main, Sep 18 2025, 22:52:34) [Clang 20.1.4 ]
Method: <function Example.date at 0x1025d5120>
Signature: (self) -> datetime.date
Return annotation: <class 'datetime.date'>
Expected: <class 'datetime.date'>
Actual type: <class 'type'>

✓ PASS: Annotation correctly resolves to datetime.date

$ uv run --python 3.14 py314_annotation_bug.py
Using CPython 3.14.2
Removed virtual environment at: .venv
Creating virtual environment at: .venv
Installed 14 packages in 14ms
Python version: 3.14.2 (main, Dec  9 2025, 19:29:30) [Clang 21.1.4 ]
Method: <function Example.date at 0x102df2770>
Signature: (self) -> <function Example.date at 0x102df2770>
Return annotation: <function Example.date at 0x102df2770>
Expected: <class 'datetime.date'>
Actual type: <class 'function'>

CPython versions tested on:

3.14

Operating systems tested on:

No response

Metadata

Metadata

Assignees

No one assigned

    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

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions