| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
| |
Automerge-Triggered-By: GH:pablogsal
|
|
|
|
|
| |
Co-authored-by: Guido van Rossum <guido@python.org>
Co-authored-by: Talin <viridia@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
|
|
|
|
| |
messages (GH-23677)
|
|
|
|
|
|
|
|
|
| |
By attempting to avoid backslashes in f-string expressions.
We also now proactively raise errors for some backslashes we can't
avoid while unparsing FormattedValues
Co-authored-by: hauntsaninja <>
Co-authored-by: Shantanu <hauntsaninja@users.noreply.github.com>
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
|
|
|
| |
Also document that eval() does this (the same way).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Partially revert commit ac46eb4ad6662cf6d771b20d8963658b2186c48c:
"bpo-38113: Update the Python-ast.c generator to PEP384 (gh-15957)".
Using a module state per module instance is causing subtle practical
problems.
For example, the Mercurial project replaces the __import__() function
to implement lazy import, whereas Python expected that "import _ast"
always return a fully initialized _ast module.
Add _PyAST_Fini() to clear the state at exit.
The _ast module has no state (set _astmodule.m_size to 0). Remove
astmodule_traverse(), astmodule_clear() and astmodule_free()
functions.
|
| |
|
| |
|
|
|
|
| |
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).
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
| |
location information (GH-20157)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
|
|
|
|
| |
(GH-17797)
|
|
|
| |
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
|
|
|
|
| |
ast.parse (GH-20134)
|
| |
|
|
|
|
|
| |
nodes (GH-19868)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
|
| |
|
| |
|
|
|
|
|
|
|
| |
* 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".
|
| |
|
|
|
|
| |
(GH-18946)
|
|
|
|
|
|
|
|
|
| |
* 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.
|
|
|
|
|
|
|
| |
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).
|
| |
|
| |
|
|
|
|
|
|
| |
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>
|
|
|
|
| |
Implement a simple precedence algorithm for ast.unparse in order to avoid redundant
parenthesis for nested structures in the final output.
|
| |
|
| |
|
| |
|
|
|
|
|
| |
regression on import (GH-17376)" (GH-17687)
This reverts commit ded8888fbc33011dd39b7b1c86a5adfacc4943f3.
|
|
|
|
|
| |
Co-Authored-By: Victor Stinner <vstinner@python.org>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
|
|
|
|
| |
Add -i and --indent (indentation level), and --no-type-comments
(type comments) command line options to ast parsing tool.
|
| |
|
|
|
|
|
|
|
|
|
| |
on import (GH-17376)
https://bugs.python.org/issue38870
Automerge-Triggered-By: @pablogsal
|
|
|
|
|
|
|
| |
(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.
|
| |
|
| |
|
|
|
|
| |
(GH-15510)
|
|
|
|
|
|
|
| |
(GH-15490)
It emits a deprecation warning and calls corresponding method
visit_Num(), visit_Str(), etc.
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
| |
(A single int is still allowed, but undocumented.)
https://bugs.python.org/issue35766
|
|
|
|
|
|
|
| |
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
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
|
| |
constants. (GH-9934)
Some projects (e.g. Chameleon) create ast.Str containing an instance
of the str subclass.
|
| |
|
| |
|
|
|
|
|
|
| |
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>
|