Skip to content

Archive

Typing

3 articles
Python 09 Sep 2026 10 min read

Introspect Deferred Annotations with Python annotationlib

Python annotations are not only for static type checkers. Frameworks use them to build dependency graphs, validators inspect them to derive schemas, and documentation tools render them for humans. That makes annotation introspection part of the runtime behavior of many Python applications. Python 3.14 changes that behavior substantially. Annotations now use deferred evaluation by default, and the standard library adds annotationlib as the dedicated low-level interface for retrieving them. The important consequence is that annotation consumers should stop assuming there is one universally correct representation. Sometimes you want actual runtime values. Sometimes unresolved names must remain inspectable. Sometimes you only need readable text and should avoid resolving names entirely.

Python 01 Sep 2026 3 min read

Use Python Protocols for Structural Typing at API Boundaries

Python often relies on duck typing: if an object supports the operation a function needs, its concrete class does not matter. typing.Protocol gives static type checkers a way to describe that idea explicitly without requiring implementations to inherit from a shared base class. Define the behavior you consume from typing import Protocol class ByteWriter(Protocol): def write(self, data: bytes) -> int: ... def emit_header(writer: ByteWriter) -> None: writer.write(b"NLR1") Any statically compatible object can satisfy ByteWriter, even if its class never mentions the protocol.

Python 01 Sep 2026 5 min read

Python Protocols and Structural Subtyping for Flexible APIs

Python code often depends on behavior rather than a specific class hierarchy. A function may only need an object with a send() method, a read() method, or a pair of repository operations. typing.Protocol lets type checkers describe those behavioral requirements directly. A class satisfies a protocol by having compatible members; it does not need to inherit from the protocol. This is structural subtyping: “if it has the required shape, it can be used here.”