PEP 846: Docstrings for Type Aliases
PEP 846 introduces support for attaching docstrings directly to type alias statements using string literals. The Python parser will now store these docstrings in a dedicated 'doc' field within the ast.TypeAlias node, enabling retrieval via ast.get_docstring(), pydoc, and help().
Verified State Diff
Impact & Verification Analysis
Python developers, library maintainers, and authors of static analysis or documentation generation tools.
It improves the discoverability of type definitions in large codebases and ensures consistent documentation standards across different Python language constructs.
Full Fact Overview
This change standardizes documentation practices for type aliases, aligning them with the behavior of functions, classes, and modules. By modifying the AST structure to include an optional 'doc' field on ast.TypeAlias, the proposal eliminates the need for auxiliary expression nodes to hold documentation. This ensures that documentation tools like pydoc and help() can natively discover and display metadata for type aliases, improving code maintainability and developer tooling consistency in static analysis workflows.