Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 4 additions & 29 deletions peps/pep-0827.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Discussions-To: https://discuss.python.org/t/pep-827-type-manipulation/106353
Status: Draft
Type: Standards Track
Topic: Typing
Requires: 849
Created: 27-Feb-2026
Python-Version: 3.16
Post-History: 02-Mar-2026
Expand Down Expand Up @@ -1401,35 +1402,9 @@ More loosely speaking, though, the use of ``if`` and ``for`` in type
annotations can cause trouble for tools that want to extract type
annotations.

Tools that want to fully evaluate the annotations will need to either
implement an evaluator or use a library for it (the PEP authors are
planning to produce such a library).

Tools that specifically rely on introspecting annotations at runtime
(tools that parse Python files are obviously unaffected) that want
to extract the annotations unevaluated and process them in some way are
possibly in more trouble. Currently, this is
doable if ``from __future__ import annotations`` is specified, because
the string annotation could be parsed with ``ast.parse`` and then handled
in arbitrary ways.

Absent that, as things currently stand, things get trickier, since
there is currently no way to get useful info out of the
``__annotate__`` functions without running the annotation, and its
tricks for building a string do not work for loops and
conditionals.

This could be mitigated by doing one of:
1. The :pep:`"Just store the strings" <649#just-store-the-strings>`
option from :pep:`649`, which would allow always extracting
unevaluated strings.
2. Adding a ``Format.AST`` mode for
fetching annotations (see this `PEP draft <#ast_format_>`_)

If neither of those options is taken, then tools that want to process
unevaluated type manipulation expressions will probably need to
reparse the source code and extract annotations from there. Which we
expect is what most tools do anyway.
To address this, we depend on :pep:`849` (or something essentially
isomorphic to it), which will allow retrieving the AST (or string)
representation of arbitrary annotations.


Security Implications
Expand Down
Loading