summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ast.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-39474: Fix AST pos for expressions like (a)(b), (a)[b] and (a).b. (GH-18477)Miss Islington (bot)2020-02-121-0/+27
| | | | | (cherry picked from commit 6e619c48b8e804ece9521453fc8da0640a04d5b1) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.8] bpo-39579: Fix Attribute end_col_offset to point at the current node ↵Lysandros Nikolaou2020-02-081-0/+8
| | | | | | | | | | | | | | | (GH-18405) (GH-18408) (cherry picked from commit d2e1098641f98594702ef29049c3c4a3f394786f) https://bugs.python.org/issue39579 Automerge-Triggered-By: @gvanrossum
* [3.8] bpo-39080: Starred Expression's column offset fix when inside a CALL ↵Pablo Galindo2019-12-181-0/+9
| | | | | | | | | | | | | | | (GH-17645) (GH-17649) … Co-Authored-By: Pablo Galindo <Pablogsal@gmail.com> (cherry picked from commit 50d4f12958bf806a4e1a1021d70cfd5d448c5cba) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> https://bugs.python.org/issue39080
* Fix elif start column offset when there is an else following (GH-17596) ↵Miss Islington (bot)2019-12-141-0/+9
| | | | | | | (GH-17600) (cherry picked from commit 5936a4ce914d42af97b9238e5090dedc8d5b0bd2) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
* bpo-39031: Include elif keyword when producing lineno/col-offset info for ↵Miss Islington (bot)2019-12-131-0/+9
| | | | | | | | | | | | if_stmt (GH-17582) (GH-17589) When parsing an "elif" node, lineno and col_offset of the node now point to the "elif" keyword and not to its condition, making it consistent with the "if" node. https://bugs.python.org/issue39031 Automerge-Triggered-By: @pablogsal (cherry picked from commit 025a602af7ee284d8db6955c26016f3f27d35536) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
* bpo-38535: Fix positions for AST nodes for calls without arguments in ↵Miss Skeleton (bot)2019-10-261-6/+6
| | | | | | | decorators. (GH-16861) (cherry picked from commit 26ae9f6d3d755734c9f371b9356325afe5764813) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.8] bpo-37950: Fix ast.dump() when call with incompletely initialized ↵Serhiy Storchaka2019-08-291-0/+29
| | | | | | node. (GH-15510) (GH-15582) (cherry picked from commit e64f948e762a6b9fd02e2902ccf42438df6fcb61)
* [3.8] bpo-36917: Add default implementation of ↵Miss Islington (bot)2019-08-261-0/+51
| | | | | | | | ast.NodeVisitor.visit_Constant(). (GH-15490) (GH-15509) It emits a deprecation warning and calls corresponding method visit_Num(), visit_Str(), etc. (cherry picked from commit c3ea41e9bf100a5396b851488c3efe208e5e2179)
* bpo-37593: Swap the positions of posonlyargs and args in the constructor of ↵Miss Islington (bot)2019-07-141-15/+15
| | | | | | | | ast.parameters nodes (GH-14778) https://bugs.python.org/issue37593 (cherry picked from commit cd6e83b4810549c308ab2d7315dbab526e35ccf6) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-18374: fix tests to check the correct thing about line numbers ↵Miss Islington (bot)2019-07-091-4/+4
| | | | | | | (GH-14659) (GH-14672) (cherry picked from commit 430a9f44fe22f029ae8cfeecb46621d7e199414b) Co-authored-by: Carl Friedrich Bolz-Tereick <cfbolz@gmx.de>
* bpo-18374: fix wrong col_offset of some ast.BinOp instances (GH-14607)Miss Islington (bot)2019-07-081-0/+30
| | | | | | | | Nested BinOp instances (e.g. a+b+c) had a wrong col_offset for the second BinOp (e.g. 2 instead of 0 in the example). Fix it by using the correct st node to copy the line and col_offset from in ast.c. (cherry picked from commit 110a47c4f42cf4db88edc1876899fff8f05190fb) Co-authored-by: Carl Friedrich Bolz-Tereick <cfbolz@gmx.de>
* bpo-37112: Allow compile to work on AST with positional only arguments with ↵Pablo Galindo2019-05-311-0/+22
| | | | defaults (GH-13697)
* bpo-36540: PEP 570 -- Implementation (GH-12701)Pablo Galindo2019-04-291-24/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit contains the implementation of PEP570: Python positional-only parameters. * Update Grammar/Grammar with new typedarglist and varargslist * Regenerate grammar files * Update and regenerate AST related files * Update code object * Update marshal.c * Update compiler and symtable * Regenerate importlib files * Update callable objects * Implement positional-only args logic in ceval.c * Regenerate frozen data * Update standard library to account for positional-only args * Add test file for positional-only args * Update other test files to account for positional-only args * Add News entry * Update inspect module and related tests
* bpo-36332: Allow compile() to handle AST objects with assignment expressions ↵Pablo Galindo2019-03-181-0/+11
| | | | | | (GH-12398)
* bpo-36280: Add Constant.kind field (GH-12295)Guido van Rossum2019-03-131-44/+62
| | | | | | | | | | | | | | The value is a string for string and byte literals, None otherwise. It is 'u' for u"..." literals, 'b' for b"..." literals, '' for "..." literals. The 'r' (raw) prefix is ignored. Does not apply to f-strings. This appears sufficient to make mypy capable of using the stdlib ast module instead of typed_ast (assuming a mypy patch I'm working on). WIP: I need to make the tests pass. @ilevkivskyi @serhiy-storchaka https://bugs.python.org/issue36280
* bpo-35766: Merge typed_ast back into CPython (GH-11645)Guido van Rossum2019-01-311-65/+66
|
* bpo-33416: Add end positions to Python AST (GH-11605)Ivan Levkivskyi2019-01-221-20/+334
| | | | | | | | | | | | | | | | | | 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-0/+4
|
* bpo-34850: Emit a warning for "is" and "is not" with a literal. (GH-9642)Serhiy Storchaka2019-01-181-5/+6
|
* bpo-16806: Fix `lineno` and `col_offset` for multi-line string tokens (GH-10021)Anthony Sottile2019-01-131-0/+19
|
* bpo-31241: Fix AST node position for list and generator comprehensions. ↵Serhiy Storchaka2018-11-271-11/+40
| | | | | | | | (GH-10633) The lineno and col_offset attributes of AST nodes for list comprehensions, generator expressions and tuples are now point to the opening parenthesis or square brace. For tuples without parenthesis they point to the position of the first item.
* bpo-34876: Change the lineno of the AST for decorated function and class. ↵Serhiy Storchaka2018-10-301-2/+14
| | | | | | | (GH-9731) It was overridden by the lineno of the first decorator. Now it is the lineno of 'def' or 'class'.
* bpo-32892: Support subclasses of base types in isinstance checks for AST ↵Serhiy Storchaka2018-10-281-0/+4
| | | | | | | 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-53/+151
|
* closes bpo-31902: Fix the col_offset attribute for ast.Async* nodes to point ↵guoci2018-09-111-4/+4
| | | | | | to the "async" keyword. (GH-4175) Previously, col_offset points to the keyword after "async".
* bpo-33851: Fix ast.get_docstring() for a node that lacks a docstring. (GH-7682)Serhiy Storchaka2018-06-151-0/+31
|
* bpo-32911: Revert bpo-29463. (GH-7121) (GH-7197)Serhiy Storchaka2018-05-291-78/+63
| | | | | | 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-8/+31
| | | | Addition and subtraction of arbitrary numbers no longer allowed.
* bpo-31592: Fix an assertion failure in Python parser in case of a bad ↵Oren Milman2017-09-301-0/+10
| | | | unicodedata.normalize(). (#3767)
* bpo-29637: clean docstring only if not None (GH-267)Matthias Bussonnier2017-02-241-0/+1
|
* bpo-29622: Make AST constructor to accept less than enough number of ↵INADA Naoki2017-02-231-4/+0
| | | | | | | | | | | positional arguments (GH-249) bpo-29463 added optional "docstring" field to 4 AST types. While it is optional, it breaks backward compatibility because AST constructor requires number of positional argument is same to number of fields. AST types accepts empty arguments, and incomplete keyword arguments. But it's not big problem because field can be filled after creation, and checked when compiling. So stop requiring complete set of fields for positional arguments too.
* bpo-29463: Add docstring field to some AST nodes. (#46)INADA Naoki2017-02-221-73/+87
| | | | | | | | | | | * 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
* Issue #28008: Implement PEP 530 -- asynchronous comprehensions.Yury Selivanov2016-09-091-16/+19
|
* Issue #27352: Fixed an error message in a test.Serhiy Storchaka2016-06-271-1/+1
|
* Issue #13436: Add a test to make sure that ast.ImportFrom(level=None) worksBerker Peksag2016-04-291-0/+11
|
* compiler: don't emit SyntaxWarning on const stmtVictor Stinner2016-02-081-5/+2
| | | | | Issue #26204: the compiler doesn't emit SyntaxWarning warnings anymore when constant statements are ignored.
* compiler now ignores constant statementsVictor Stinner2016-02-081-17/+16
| | | | | | | | | | | | | | | | | | | The compile ignores constant statements and emit a SyntaxWarning warning. Don't emit the warning for string statement because triple quoted string is a common syntax for multiline comments. Don't emit the warning on ellipis neither: 'def f(): ...' is a legit syntax for abstract functions. Changes: * test_ast: ignore SyntaxWarning when compiling test statements. Modify test_load_const() to use assignment expressions rather than constant expression. * test_code: add more kinds of constant statements, ignore SyntaxWarning when testing that the compiler removes constant statements. * test_grammar: ignore SyntaxWarning on the statement "1"
* Simplify main() of test_astVictor Stinner2016-02-081-2/+3
| | | | | | | * Use ast.parse() to get the AST for a statement * Use str%args syntax for format a line Issue #26204.
* Issue #26146: enhance ast.Constant error messageVictor Stinner2016-01-261-0/+6
| | | | | | | Mention the name of the invalid type in error message of AST validation for constants. Suggestion made by Joseph Jevnik on a review.
* Add ast.ConstantVictor Stinner2016-01-251-1/+119
| | | | | | | | | | | | | | | | | | | | | 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
* make opening brace of container literals and comprehensions correspond to ↵Benjamin Peterson2015-09-261-9/+9
| | | | the line number and col offset of the AST node (closes #25131)
* Issue #24975: Fix AST compilation for PEP 448 syntax.Yury Selivanov2015-09-011-9/+15
|
* Issue #24688: ast.get_docstring() for 'async def' functions.Yury Selivanov2015-07-231-0/+3
|
* PEP 0492 -- Coroutines with async and await syntax. Issue #24017.Yury Selivanov2015-05-121-0/+9
|
* PEP 448: additional unpacking generalizations (closes #2292)Benjamin Peterson2015-05-061-35/+21
| | | | Patch by Neil Girdhar.
* revert lineno and col_offset changes from #16795 (closes #21295)Benjamin Peterson2015-02-021-31/+14
|
* set line and column numbers for keyword-only arg nodes (closes #20619)Benjamin Peterson2014-02-141-2/+2
|
* #18466: merge with 3.3.Ezio Melotti2013-08-171-1/+1
|\
| * #18466: fix more typos. Patch by Févry Thibault.Ezio Melotti2013-08-171-1/+1
| |
* | Update various test modules to use unittest.main() for test discoveryBrett Cannon2013-06-131-4/+1
| | | | | | | | instead of manually listing tests for test.support.run_unittest().