summaryrefslogtreecommitdiffstats
path: root/Lib/ast.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-36290: Fix keytword collision handling in AST node constructors (GH-12382)Rémi Lapeyre2020-05-241-0/+7
|
* bpo-38870: Don't omit parenthesis when unparsing a slice in ast.unparseBatuhan Taskaya2020-05-181-1/+11
| | | | When unparsing a non-empty tuple, the parentheses can be safely omitted if there aren't any elements that explicitly require them (such as starred expressions).
* bpo-38870: correctly escape unprintable characters on ast.unparse (GH-20166)CyberSaxosTiGER2020-05-181-3/+11
| | | | | | | | | Unprintable characters such as `\x00` weren't correctly roundtripped due to not using default string repr when generating docstrings. This patch correctly encodes all unprintable characters (except `\n` and `\t`, which are commonly used for formatting, and found unescaped). Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
* bpo-40662: Fixed ast.get_source_segment for ast nodes that have incomplete ↵Irit Katriel2020-05-181-0/+2
| | | | | location information (GH-20157) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-38870: Implement round tripping support for typed AST in ast.unparse ↵Batuhan Taskaya2020-05-161-6/+23
| | | | (GH-17797)
* bpo-38870: Correctly handle empty docstrings in ast.unparse (GH-18768)Batuhan Taskaya2020-05-161-5/+8
| | | Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-38870: Don't put unnecessary parentheses on class declarations in ↵Batuhan Taskaya2020-05-161-1/+1
| | | | ast.parse (GH-20134)
* bpo-38870: Do not separate factor prefixes in ast.unparse (GH-20133)Batuhan Taskaya2020-05-161-3/+6
|
* bpo-40355: Improve error messages in ast.literal_eval with malformed Dict ↵Curtis Bucher2020-05-051-4/+7
| | | | | nodes (GH-19868) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-38870: Don't start generated output with newlines in ast.unparse (GH-19636)Batuhan Taskaya2020-05-031-4/+10
|
* Fix typo in exception thrown by ast.unparse (GH-19534)Shantanu2020-04-161-1/+1
|
* bpo-39999: Improve compatibility of the ast module. (GH-19056)Serhiy Storchaka2020-03-221-2/+24
| | | | | | | * Re-add removed classes Suite, slice, Param, AugLoad and AugStore. * Add docstrings for dummy classes. * Add docstrings for attribute aliases. * Set __module__ to "ast" instead of "_ast".
* bpo-38870: Implement support for ast.FunctionType in ast.unparse (GH-19016)Batuhan Taşkaya2020-03-151-0/+9
|
* Fix syntax error in an example in the ast documentation and sync docstrings ↵Pablo Galindo2020-03-121-2/+2
| | | | (GH-18946)
* bpo-34822: Simplify AST for subscription. (GH-9605)Serhiy Storchaka2020-03-101-12/+21
| | | | | | | | | * Remove the slice type. * Make Slice a kind of the expr type instead of the slice type. * Replace ExtSlice(slices) with Tuple(slices, Load()). * Replace Index(value) with a value itself. All non-terminal nodes in AST for expressions are now of the expr type.
* bpo-36287: Make ast.dump() not output optional fields and attributes with ↵Serhiy Storchaka2020-03-091-20/+26
| | | | | | | default values. (GH-18843) The default values for optional fields and attributes of AST nodes are now set as class attributes (e.g. Constant.kind is set to None).
* bpo-38870: Simplify sequence interleaves in ast.unparse (GH-17892)Batuhan Taşkaya2020-03-091-23/+14
|
* bpo-39889: Fix ast.unparse() for subscript. (GH-18824)Serhiy Storchaka2020-03-071-2/+17
|
* bpo-38870: Add docstring support to ast.unparse (GH-17760)Batuhan Taşkaya2020-03-021-10/+45
| | | | | | Allow ast.unparse to detect docstrings in functions, modules and classes and produce nicely formatted unparsed output for said docstrings. Co-Authored-By: Pablo Galindo <Pablogsal@gmail.com>
* bpo-38870: Implement a precedence algorithm in ast.unparse (GH-17377)Batuhan Taşkaya2020-03-011-15/+123
| | | | Implement a simple precedence algorithm for ast.unparse in order to avoid redundant parenthesis for nested structures in the final output.
* bpo-39524: Fixed doc-string in ast._pad_whitespace (GH-18340)mpheath2020-02-131-1/+1
|
* bpo-39158: ast.literal_eval() doesn't support empty sets (GH-17742)Raymond Hettinger2020-01-031-0/+3
|
* bpo-38870: Throw ValueError on invalid yield from usage (GH-17798)Batuhan Taşkaya2020-01-021-4/+4
|
* Revert "bpo-38870: Remove dependency on contextlib to avoid performance ↵Pablo Galindo2019-12-231-13/+6
| | | | | regression on import (GH-17376)" (GH-17687) This reverts commit ded8888fbc33011dd39b7b1c86a5adfacc4943f3.
* bpo-38870: Refactor delimiting with context managers in ast.unparse (GH-17612)Batuhan Taşkaya2019-12-231-147/+137
| | | | | Co-Authored-By: Victor Stinner <vstinner@python.org> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* bpo-38348: Extend command line options of ast parsing tool (GH-16540)Batuhan Taşkaya2019-12-161-2/+6
| | | | Add -i and --indent (indentation level), and --no-type-comments (type comments) command line options to ast parsing tool.
* bpo-38870: Remove dead code related with argument unparsing (GH-17613)Batuhan Taşkaya2019-12-161-5/+2
|
* bpo-38870: Remove dependency on contextlib to avoid performance regression ↵Pablo Galindo2019-11-251-7/+13
| | | | | | | | | on import (GH-17376) https://bugs.python.org/issue38870 Automerge-Triggered-By: @pablogsal
* bpo-38870: Expose a function to unparse an ast object in the ast module ↵Pablo Galindo2019-11-241-0/+693
| | | | | | | (GH-17302) Add ast.unparse() as a function in the ast module that can be used to unparse an ast.AST object and produce a string with code that would produce an equivalent ast.AST object when parsed.
* bpo-38049: Add command-line interface for the ast module. (GH-15724)Serhiy Storchaka2019-09-091-0/+24
|
* bpo-37995: Add an option to ast.dump() to produce a multiline output. (GH-15631)Serhiy Storchaka2019-09-091-11/+34
|
* bpo-37950: Fix ast.dump() when call with incompletely initialized node. ↵Serhiy Storchaka2019-08-291-15/+24
| | | | (GH-15510)
* bpo-36917: Add default implementation of ast.NodeVisitor.visit_Constant(). ↵Serhiy Storchaka2019-08-261-0/+31
| | | | | | | (GH-15490) It emits a deprecation warning and calls corresponding method visit_Num(), visit_Str(), etc.
* bpo-35766: compile(): rename feature_version parameter (GH-13994)Victor Stinner2019-06-121-1/+1
| | | | | | Rename compile() feature_version parameter to _feature_version and convert it to a keyword-only parameter. Update also test_type_comments to pass feature_version as a tuple.
* bpo-35766: Change format for feature_version to (major, minor) (GH-13992)Guido van Rossum2019-06-121-1/+8
| | | | | | | (A single int is still allowed, but undocumented.) https://bugs.python.org/issue35766
* bpo-35975: Support parsing earlier minor versions of Python 3 (GH-12086)Guido van Rossum2019-03-071-2/+4
| | | | | | | This adds a `feature_version` flag to `ast.parse()` (documented) and `compile()` (hidden) that allow tweaking the parser to support older versions of the grammar. In particular if `feature_version` is 5 or 6, the hacks for the `async` and `await` keyword from PEP 492 are reinstated. (For 7 or higher, these are unconditionally treated as keywords, but they are still special tokens rather than `NAME` tokens that the parser driver recognizes.) https://bugs.python.org/issue35975
* bpo-35766: Merge typed_ast back into CPython (GH-11645)Guido van Rossum2019-01-311-2/+6
|
* bpo-33416: Add end positions to Python AST (GH-11605)Ivan Levkivskyi2019-01-221-8/+92
| | | | | | | | | | | | | | | | | | The majority of this PR is tediously passing `end_lineno` and `end_col_offset` everywhere. Here are non-trivial points: * It is not possible to reconstruct end positions in AST "on the fly", some information is lost after an AST node is constructed, so we need two more attributes for every AST node `end_lineno` and `end_col_offset`. * I add end position information to both CST and AST. Although it may be technically possible to avoid adding end positions to CST, the code becomes more cumbersome and less efficient. * Since the end position is not known for non-leaf CST nodes while the next token is added, this requires a bit of extra care (see `_PyNode_FinalizeEndPos`). Unless I made some mistake, the algorithm should be linear. * For statements, I "trim" the end position of suites to not include the terminal newlines and dedent (this seems to be what people would expect), for example in ```python class C: pass pass ``` the end line and end column for the class definition is (2, 8). * For `end_col_offset` I use the common Python convention for indexing, for example for `pass` the `end_col_offset` is 4 (not 3), so that `[0:4]` gives one the source code that corresponds to the node. * I added a helper function `ast.get_source_segment()`, to get source text segment corresponding to a given AST node. It is also useful for testing. An (inevitable) downside of this PR is that AST now takes almost 25% more memory. I think however it is probably justified by the benefits.
* bpo-35733: Make isinstance(ast.Constant(boolean), ast.Num) be false. (GH-11547)Anthony Sottile2019-01-181-1/+7
|
* bpo-32892: Support subclasses of base types in isinstance checks for AST ↵Serhiy Storchaka2018-10-281-1/+1
| | | | | | | constants. (GH-9934) Some projects (e.g. Chameleon) create ast.Str containing an instance of the str subclass.
* bpo-32892: Use ast.Constant instead of specific constant AST types. (GH-9445)Serhiy Storchaka2018-09-271-9/+64
|
* bpo-33851: Fix ast.get_docstring() for a node that lacks a docstring. (GH-7682)Serhiy Storchaka2018-06-151-2/+2
|
* bpo-32911: Revert bpo-29463. (GH-7121) (GH-7197)Serhiy Storchaka2018-05-291-1/+9
| | | | | | Remove the docstring attribute of AST types and restore docstring expression as a first stmt in their body. Co-authored-by: INADA Naoki <methane@users.noreply.github.com>
* bpo-31778: Make ast.literal_eval() more strict. (#4035)Serhiy Storchaka2018-01-041-15/+21
| | | | Addition and subtraction of arbitrary numbers no longer allowed.
* bpo-29637: clean docstring only if not None (GH-267)Matthias Bussonnier2017-02-241-1/+4
|
* bpo-29463: Add docstring field to some AST nodes. (#46)INADA Naoki2017-02-221-9/+1
| | | | | | | | | | | * bpo-29463: Add docstring field to some AST nodes. ClassDef, ModuleDef, FunctionDef, and AsyncFunctionDef has docstring field for now. It was first statement of there body. * fix document. thanks travis! * doc fixes
* Add ast.ConstantVictor Stinner2016-01-251-22/+30
| | | | | | | | | | | | | | | | | | | | | Issue #26146: Add a new kind of AST node: ast.Constant. It can be used by external AST optimizers, but the compiler does not emit directly such node. An optimizer can replace the following AST nodes with ast.Constant: * ast.NameConstant: None, False, True * ast.Num: int, float, complex * ast.Str: str * ast.Bytes: bytes * ast.Tuple if items are constants too: tuple * frozenset Update code to accept ast.Constant instead of ast.Num and/or ast.Str: * compiler * docstrings * ast.literal_eval() * Tools/parser/unparse.py
* Issue #25670: Remove duplicate getattr() from ast.NodeTransformerVictor Stinner2015-11-201-1/+0
|
* Issue #24688: ast.get_docstring() for 'async def' functions.Yury Selivanov2015-07-231-1/+1
|
* create NameConstant AST class for None, True, and False literals (closes #16619)Benjamin Peterson2012-12-061-4/+2
|