Skip to content

__annotations__ not defined at module level #137159

@PierreQuentel

Description

@PierreQuentel

Bug report

Bug description:

In Python 3.13 ("stock semantics") this code

x: int
print(__annotations__)

prints

{'x': <class 'int'>}

In Python 3.14 rc1 we get an error message:

Traceback (most recent call last):
  File "D:\brython\20221025\www\tests\module2.py", line 2, in <module>
    print(__annotations__)
          ^^^^^^^^^^^^^^^
NameError: name '__annotations__' is not defined. Did you mean: '__annotate__'?

Using module annotationlib changes the result:

x: int

import annotationlib
import sys

print('with annotationlib', annotationlib.get_annotations(sys.modules[__name__]))
print('__annotations__', __annotations__)

prints

with annotationlib {'x': <class 'int'>}
__annotations__ {'x': <class 'int'>}

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

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions