PEP 649 behavior for partially executed modules #130907
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
type-bug
An unexpected behavior, bug, or error
Bug report
Bug description:
Consider this package:
On 3.13, this produces:
But on main, we get this:
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
The text was updated successfully, but these errors were encountered: