Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork55
Modified fork of CPython's ast module that parses `# type:` comments
License
python/typed_ast
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This project is no longer maintained.
Use the standard libraryast
module instead.See#179.
typed_ast
is a Python 3 package that provides a Python 2.7 and Python 3parser similar to the standardast
library. Unlikeast
up to Python 3.7, the parsers intyped_ast
includePEP 484 typecomments and are independent of the version of Python under which they are run.Thetyped_ast
parsers produce the standard Python AST (plus type comments),and are both fast and correct, as they are based on the CPython 2.7 and 3.7parsers.typed_ast
runs on CPython 3.6-3.10 on Linux, OS X and Windows.
Note: Starting with Python 3.8, we recommend to use the nativeast
parser(see below).
This project is a (mostly) drop-in replacement for the builtinast
module. It isintended to be bug-for-bug compatible and behave identically, except for thepresence of a few additional fields on the returned classes and a fewadditional optional arguments to theparse
call. Therefore,typed_ast
willnot accept any bugfixes for bugs inast
-- they should be fixed upstreaminstead. To avoid feature bloat, any new features fortyped_ast
should havethe potential to be broadly useful and not be built just for one niche usecaseor in a manner such that only one project can use them.
For the purposes ofconsuming syntax trees, this should be a drop-in replacement.It is not a drop-in replacement for users that wish to create or transform ASTs,as a number of syntax tree classes have additional fields that must be populatedwhen constructing them.
Due to reliance on certain C APIs, this library does not build on and thereareno plans to support PyPy.
typed_ast
will not be updated to support parsing Python 3.8 andnewer. Instead, it is recommended to use the stdlibast
modulethere, which has been augmented to support extracting type commentsand has limited support for parsing older versions of Python 3.
Theast3
parser produces the AST from a Python 3 code, up to Python 3.7.(For rationale and technicaldetails, seehere.) The AST it currently produces is described inast3/Parser/Python.asdl. If you wish to limitparsing to older versions of Python 3,ast3
can be configured to to give aSyntaxError for new syntax features introduced beyond a given Python version.For more information, see the module docstring intyped_ast/ast3.py.
Theast27
parser tracks the standard Python 2.7 AST, which is expected tonever receive further updates. The AST it produces is described inast27/Parser/Python.asdl. For more information,see the module docstring intyped_ast/ast27.py.
typed_ast
also provides aconversions
module which convertsast27
ASTsintoast3
ASTs. This functionality is somewhat experimental, however. Formore information, see thepy2to3
docstring intyped_ast/conversions.
Note: as these parsers consider type comments part of the grammar, incorrectlyplaced type comments are considered syntax errors.
To make a newtyped_ast
release, seerelease_process.md
.
About
Modified fork of CPython's ast module that parses `# type:` comments
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.