From 0d2725a33ca3936ded19504149664eb58108a845 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Wed, 30 Sep 2026 14:30:10 -0700 Subject: [PATCH] PEP 827: Depend on PEP 849 --- peps/pep-0827.rst | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/peps/pep-0827.rst b/peps/pep-0827.rst index bf3200325bf..0df2ebf9b0b 100644 --- a/peps/pep-0827.rst +++ b/peps/pep-0827.rst @@ -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 @@ -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