ruff/crates/ty_python_semantic/resources/mdtest/scopes/annotate_global.md
Dan Parizher 346842f003
[pyflakes] Fix false positives for __annotate__ (Py3.14+) and __warningregistry__ (F821) (#20154)
## Summary

Fixes #19970

---------

Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
2025-09-23 08:16:00 -04:00

745 B

__annotate__ as an implicit global is version-gated (Py3.14+)

Absent before 3.14

__annotate__ is never present in the global namespace on Python <3.14.

[environment]
python-version = "3.13"
# error: [unresolved-reference]
reveal_type(__annotate__)  # revealed: Unknown

Present in 3.14+

The __annotate__ global may be present in Python 3.14, but only if at least one global symbol in the module is annotated (e.g. x: int or x: int = 42). Currently we model __annotate__ as always being possibly unbound on Python 3.14+.

[environment]
python-version = "3.14"
# error: [possibly-unresolved-reference]
reveal_type(__annotate__)  # revealed: (format: int, /) -> dict[str, Any]