Advancing Python typing
By Steven Van ·
Vercel proposes PEP 827, a year-long effort to bring TypeScript-style programmable types to Python without plugins or boilerplate.
Vercel has published PEP 827: Type Manipulation, the outcome of a year-long research effort to make Python's type system more expressive and composable, closer in spirit to the programmable types in TypeScript but built for Python's runtime model.
Python's runtime lets classes, methods and whole APIs be generated dynamically through metaprogramming and decorators, but its static typing usually cannot follow along without typechecker plugins or extra boilerplate. PEP 827 proposes a set of standard, type-level building blocks for introspecting existing types and constructing new ones, meant to help both type checkers and runtime tooling. As an example, Vercel shows how TypeScript's Pick and Omit utility types could be implemented in Python with these building blocks: Python's version uses standard imperative syntax combined with type-level APIs rather than TypeScript's dedicated typing syntax, and the Omit implementation turns out to be nearly identical to Pick, just with the condition inverted. Vercel says the point isn't to make Python look like TypeScript, but to give Python typing a programmable core that matches Python's semantics and stays introspectable at runtime, so frameworks like Pydantic could benefit too.
FastAPI creator Sebastián Ramírez responded to the proposal on the Python Discourse. As a PEP, it now goes through the standard process of debate, revision and possible rejection.
