types-typed-ast provides static type annotations (stubs) for the `typed-ast` library, enabling type checkers like MyPy to understand its API and catch type-related errors. It is part of the `typeshed` project, a community-maintained repository of type stubs for Python packages. The current version is 1.5.8.7, and `typeshed` releases new stubs regularly as upstream libraries evolve.
pip install types-typed-astVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `typed-ast` (the runtime library) and how `types-typed-ast` (the stub package) provides type hints for it. The `mypy` command would use the installed stubs to verify type correctness of `analyze_node`'s arguments and return types without any explicit import of `types-typed-ast`.
Always import symbols from the *runtime library* (`typed-ast`), not the stub package. The stub package is consumed implicitly by type checkers like MyPy.
Ensure both `pip install typed-ast` and `pip install types-typed-ast` are executed. `typed-ast` for runtime, `types-typed-ast` for type checking.
When encountering unexpected type errors, ensure your `types-typed-ast` version is compatible with your `typed-ast` version. Consult the `typeshed` repository or `typed-ast` documentation for compatibility notes. Upgrading both packages might resolve the issue.