Skip to content
IJK

PEP 827 and Runtime Annotations: What the Write-Up Says It Needs

By IJK ·

Why the Language Summit write-up says PEP 827 needs unevaluated types at runtime, and the __annotate__() design and string option it describes.

What the PEP proposes

Return types could be inferred from a function’s input parameter types. [1]

Another use-case PEP 827 serves is generating new types programmatically, such as for CRUD (Create, Read, Update, Delete) web applications, where a single database table typically has a separate ORM model definition for each CRUD operation. [2]

Comprehension types can have conditional if clauses, just like regular comprehensions. [3]

Why storage matters at runtime

Popular libraries like Pydantic and FastAPI use type annotations at runtime to drive their behavior. “This was complicated by our desire to use Python-y syntax”, like if, for, and dot notation. [4]

In concrete terms, Python will itself evaluate the types at runtime. [5]

In order to implement everything in PEP 827, there would need to be a way to access the unevaluated type even after Python had [6]

string format returns itType annotation__annotate__() functionthe draft is designed around calling itLibrary at runtimeneeds access to the unevaluated type
What does the write-up say a library needs from an annotation at runtime?

The options the write-up describes

As currently drafted, “the PEP is carefully designed to support an evaluator that works by calling the __annotate__() functions”. [7]

One of the original ideas considered by the PEP that moved to __annotate__() functions was “can we just store the strings?” The most straightforward option would be for __annotate__() to support STRING in addition to VALUE and VALUE_WITH_FAKE_GLOBALS. [8]

The __annotate__() function would get a little bigger, but if STRING is passed as the format, it would return the strings “instead of requiring the library to do something complicated to get there”. [9]

Sources

  1. The Python Software Foundation source says: Return types could be inferred from a function’s input parameter types. PEP 827: Type Manipulation (Python Language Summit 2026)
  2. The Python Software Foundation source says: Another use-case PEP 827 serves is generating new types programmatically, such as for CRUD (Create, Read, Update, Delete) web applications, where a single database table typically has a separate ORM model definition for each CRUD operation. PEP 827: Type Manipulation (Python Language Summit 2026)
  3. The Python Software Foundation source says: Comprehension types can have conditional if clauses, just like regular comprehensions. PEP 827: Type Manipulation (Python Language Summit 2026)
  4. The Python Software Foundation source says: Popular libraries like Pydantic and FastAPI use type annotations at runtime to drive their behavior. “This was complicated by our desire to use Python-y syntax”, like if, for, and dot notation. PEP 827: Type Manipulation (Python Language Summit 2026)
  5. The Python Software Foundation source says: In concrete terms, Python will itself evaluate the types at runtime. PEP 827: Type Manipulation (Python Language Summit 2026)
  6. The Python Software Foundation source says: In order to implement everything in PEP 827, there would need to be a way to access the unevaluated type even after Python had PEP 827: Type Manipulation (Python Language Summit 2026)
  7. The Python Software Foundation source says: As currently drafted, “the PEP is carefully designed to support an evaluator that works by calling the __annotate__() functions”. PEP 827: Type Manipulation (Python Language Summit 2026)
  8. The Python Software Foundation source says: One of the original ideas considered by the PEP that moved to __annotate__() functions was “can we just store the strings?” The most straightforward option would be for __annotate__() to support STRING in addition to VALUE and VALUE_WITH_FAKE_GLOBALS. PEP 827: Type Manipulation (Python Language Summit 2026)
  9. The Python Software Foundation source says: The __annotate__() function would get a little bigger, but if STRING is passed as the format, it would return the strings “instead of requiring the library to do something complicated to get there”. PEP 827: Type Manipulation (Python Language Summit 2026)

Editorial (AI-assisted; automatically checked, not human-reviewed). Each statement is linked to its source; check the source before relying on a detail.

  • python
  • typing
  • pep
  • annotations