Idea: Simpler and More Expressive Type Annotations

The Python-level AST objects are relatively expensive. Dino opened an issue about improving this (Have internal immutable AST nodes · Issue #140514 · python/cpython · GitHub) but not sure when or if that will land.

It might make sense to have a separate third-party library that evaluates annotations in C (or Rust?) for speed, so we can keep the standard library implementation relatively simple but users like Pydantic that care about speed can use a faster version. Such a library could also allow backporting new syntax to earlier versions of CPython.

I wouldn’t be so sure. Memory usage was a major motivation for PEP 563 and 649: people were noticing significant memory usage from typing objects, and those weren’t huge either.

1 Like