Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PEP 649 behavior for partially executed modules #130907

Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@JelleZijlstra

Description

@JelleZijlstra

Bug report

Bug description:

Consider this package:

$ ls recmod/__main__.pya.pyb.py$ cat recmod/__main__.py from . import aprint(a.__annotations__)$ cat recmod/a.py v1: intfrom . import bv2: int$ cat recmod/b.py from . import aprint(a.__annotations__)

On 3.13, this produces:

$ python3.13 -m recmod{'v1': <class 'int'>}{'v1': <class 'int'>, 'v2': <class 'int'>}

But on main, we get this:

$ ~/py/cpython/python.exe -m recmod{}{}

This is because we only set the__annotate__ function at the end of the module execution, so when we access annotations on the partially executed module a (inb.py), there aren't any yet. But this also populates the__annotations__ cache, so even accesses to__annotations__ after a has been fully executed still return an empty dictionary.

Should we fix this and how? I don't care much what happens if you access__annotations__ while the module is partially evaluated. However, it seems bad that such access poisons the cache forever. To fix that, we should makeModuleType.__annotations__ not cache its return value if the module is not yet fully evaluated.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp