Registry / type-stubs / typed-ast

typed-ast

JSON →
library1.5.5pypypi✓ verified 25d ago

typed-ast is a Python 3 package that provided parsers for Python 2.7 and Python 3 (up to 3.7) Abstract Syntax Trees (ASTs). Unlike the standard `ast` module before Python 3.8, it included support for PEP 484 type comments and was independent of the Python version it was run on. The project is currently at version 1.5.5 and is no longer actively maintained, with recommendations to use the built-in `ast` module for Python 3.8+.

pip install typed-ast
INSTALL
IMPORT
SIG · TYPED-AST
T
typed-ast
type-stubspythonv1.5.5
Install
1.7s avg
Import
Disk
21MB
Pass rate
6/ 10
Env Coverage6 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.5.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 1.6s
py 3.11
✓ —
✓ 1.7s
py 3.12
✕ build_error
✕ build_error
py 3.13
✕ build_error
✕ build_error
py 3.9
✓ —
✓ 1.8s
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ast3
import typed_ast.ast3
from typed_ast import ast3

This quickstart demonstrates parsing Python 3 code containing PEP 484 type comments using `typed_ast.ast3.parse`. The `typed_ast` module was specifically designed to handle these comments, which the standard `ast` module in Python versions prior to 3.8 did not expose directly in the AST. For Python 3.8 and newer, the standard `ast` module can often be used instead.

from typed_ast import ast3 code_to_parse = """ def example_function(a: int, b) -> str: result = a + int(b) # type: ignore return str(result) """ try: tree = ast3.parse(code_to_parse) print("Successfully parsed code with type comments.") # You can then traverse the AST, for example: # import ast # print(ast.dump(tree, indent=4)) except SyntaxError as e: print(f"Syntax error during parsing: {e}") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingThe `typed-ast` project is no longer actively maintained. Its primary functionality (parsing type comments) was merged into the standard library `ast` module starting with Python 3.8. It does not support parsing syntax introduced in Python 3.8 or newer.
fix
For projects targeting Python 3.8 and newer, migrate to the standard library `ast` module. For projects requiring Python 3.7 or older, `typed-ast` may still be necessary, but be aware of its unmaintained status. Consider conditional imports or dropping support for older Python versions.
affects: All versions
gotchaInstallation can fail with 'Failed building wheel for typed-ast' errors, especially on Windows, if C/C++ build tools (like Microsoft Visual C++ Build Tools) are not installed, as `typed-ast` contains C extensions.
fix
Ensure that the necessary C/C++ compiler toolchain is installed for your operating system (e.g., 'Desktop development with C++' workload for Visual Studio on Windows, `build-essential` on Debian/Ubuntu, or Xcode command line tools on macOS).
affects: All versions
gotchaWhen modifying or creating ASTs using `typed-ast`, it is not always a direct drop-in replacement for the standard `ast` module. Some `typed-ast` classes have additional fields (e.g., for type comments) that must be populated, which can lead to unexpected behavior or errors if not handled.
fix
Carefully review the `typed-ast` source code or documentation (if available) for the specific AST node classes you are working with to understand any additional fields that need to be managed during AST construction or transformation.
affects: All versions
gotchaThe `typed-ast` library does not support PyPy and there are no plans for future support due to its reliance on specific CPython C APIs.
fix
Do not use `typed-ast` in environments running PyPy. Use CPython or an alternative AST parsing solution if PyPy compatibility is required.
affects: All versions
Upgrade
Version history
1.5.5latest on PyPI · released Jul 4, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
typed-ast — pip install typed-ast · libregistry