Commit Graph

38 Commits

Author SHA1 Message Date
Nikita Sobolev c1c5882359
gh-100518: Add tests for `ast.NodeTransformer` (#100521) 2023-01-21 21:44:41 +00:00
Shantanu 200c9a8da0
gh-92986: Fix ast.unparse when ImportFrom.level is None (#92992)
This doesn't happen naturally, but is allowed by the ASDL and compiler.
We don't want to change ASDL for backward compatibility reasons
(#57645, #92987)
2022-09-05 20:14:50 +03:00
Batuhan Taskaya f6fd8aac13
gh-92671: Don't omit parentheses when unparsing empty tuples (GH-92673) 2022-05-16 13:38:06 +01:00
Jeremy Kloth 0f68c208fa
bpo-47131: Speedup AST comparisons in test_unparse by using node traversal (GH-32132) 2022-04-02 02:54:04 +01:00
Matthew Rahtz e8e737bcf6
bpo-43224: Implement PEP 646 grammar changes (GH-31018)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2022-03-26 09:55:35 -07:00
Irit Katriel d60457a667
bpo-45292: [PEP-654] add except* (GH-29581) 2021-12-14 16:48:15 +00:00
Christian Clauss 745c9d9dfc
Fix typos in the Lib directory (GH-28775)
Fix typos in the Lib directory as identified by codespell.

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
2021-10-06 16:13:48 -07:00
Batuhan Taskaya 51cef8be8c
bpo-44142: drop redundant parantheses when unparsing tuples as assignment targets (GH-26156) 2021-05-16 16:33:22 +03:00
Batuhan Taskaya e4e931a67e
bpo-44081: improve ast.unparse() for lambdas with no parameters (GH-26000) 2021-05-15 15:55:53 +03:00
Batuhan Taskaya 3d98ececda
bpo-43417: Better buffer handling for ast.unparse (GH-24772) 2021-05-09 02:32:04 +03:00
Nick Coghlan 1e7b858575
bpo-43892: Make match patterns explicit in the AST (GH-25585)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
2021-04-28 22:58:44 -07:00
Kodi Arfer 08ff4369af
bpo-43521: Allow ast.unparse with empty sets and NaN (GH-24897)
Automerge-Triggered-By: GH:pablogsal
2021-03-18 10:36:06 -07:00
Shantanu a993e901eb
bpo-28002: Roundtrip f-strings with ast.unparse better (#19612)
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>
2020-11-21 00:16:42 +03:00
Batuhan Taskaya dd74b6fde3
bpo-38870: invalid escape sequence (GH-20240)
`/home/isidentical/cpython/cpython/Lib/test/test_unparse.py:333: DeprecationWarning: invalid escape sequence \X`

Automerge-Triggered-By: @pablogsal
2020-05-19 15:14:14 -07:00
Batuhan Taskaya c102a14825
bpo-38870: Don't omit parenthesis when unparsing a slice in ast.unparse
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).
2020-05-18 21:48:49 +01:00
CyberSaxosTiGER d71a6492db
bpo-38870: correctly escape unprintable characters on ast.unparse (GH-20166)
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>
2020-05-18 19:41:35 +01:00
Pablo Galindo 6341fc7257
bpo-38870: Use subTest in test_unparse for better error reporting (GH-20141) 2020-05-17 03:53:57 +01:00
Batuhan Taskaya dff92bb31f
bpo-38870: Implement round tripping support for typed AST in ast.unparse (GH-17797) 2020-05-17 00:04:12 +01:00
Batuhan Taskaya e966af7cff
bpo-38870: Correctly handle empty docstrings in ast.unparse (GH-18768)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2020-05-16 23:49:07 +01:00
Batuhan Taskaya 25160cdc47
bpo-38870: Don't put unnecessary parentheses on class declarations in ast.parse (GH-20134) 2020-05-16 22:53:25 +01:00
Batuhan Taskaya ce4a753dcb
bpo-38870: Do not separate factor prefixes in ast.unparse (GH-20133) 2020-05-16 22:46:11 +01:00
Batuhan Taskaya 493bf1cc31
bpo-38870: Don't start generated output with newlines in ast.unparse (GH-19636) 2020-05-03 18:11:51 +01:00
Pablo Galindo ea7297cf8f
bpo-40334: unskip test_function_type in test_unparse with the new parser (GH-19837) 2020-05-01 08:02:06 -07:00
Victor Stinner 57572b103e
bpo-40443: Remove unused imports in tests (GH-19805) 2020-04-30 01:48:37 +02:00
Victor Stinner 1def7754b7
bpo-40334: Rename PyConfig.use_peg to _use_peg_parser (GH-19670)
* Rename PyConfig.use_peg to _use_peg_parser
* Document PyConfig._use_peg_parser and mark it a deprecated
* Mark -X oldparser option and PYTHONOLDPARSER env var as deprecated
  in the documentation.
* Add use_old_parser() and skip_if_new_parser() to test.support
* Remove sys.flags.use_peg: use_old_parser() uses
  _testinternalcapi.get_configs() instead.
* Enhance test_embed tests
* subprocess._args_from_interpreter_flags() copies -X oldparser
2020-04-23 03:03:24 +02:00
Pablo Galindo c5fc156852
bpo-40334: PEP 617 implementation: New PEG parser for CPython (GH-19503)
Co-authored-by: Guido van Rossum <guido@python.org>
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2020-04-22 23:29:27 +01:00
Hakan Çelik 6a5bf15c71
bpo-40209: Use tokenize.open in test_unparse (GH-19399) 2020-04-16 11:11:55 +01:00
Batuhan Taşkaya 5b66ec166b
bpo-38870: Implement support for ast.FunctionType in ast.unparse (GH-19016) 2020-03-15 19:56:57 +00:00
Batuhan Taşkaya e7cab7f780
bpo-38870: Simplify sequence interleaves in ast.unparse (GH-17892) 2020-03-09 20:27:03 +00:00
Serhiy Storchaka c4928fc1a8
bpo-39889: Fix ast.unparse() for subscript. (GH-18824) 2020-03-07 17:25:32 +02:00
Batuhan Taşkaya 89aa4694fc
bpo-38870: Add docstring support to ast.unparse (GH-17760)
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>
2020-03-02 18:59:01 +00:00
Batuhan Taşkaya 397b96f6d7
bpo-38870: Implement a precedence algorithm in ast.unparse (GH-17377)
Implement a simple precedence algorithm for ast.unparse in order to avoid redundant
parenthesis for nested structures in the final output.
2020-03-01 20:12:17 +00:00
Batuhan Taşkaya 7b35bef978 bpo-38870: Throw ValueError on invalid yield from usage (GH-17798) 2020-01-02 18:20:04 +00:00
Pablo Galindo be287c3191
Fix error when running with -uall in test_unparse (GH-17739) 2019-12-29 20:18:36 +00:00
Pablo Galindo 23a226bf3a
bpo-38870: Run always tests that heavily use grammar features in test_unparse (GH-17738) 2019-12-29 19:20:55 +00:00
Pablo Galindo e9df88e8e9
Clean imports in test_unparse (GH-17545) 2019-12-10 00:37:47 +00:00
Pablo Galindo ac229116a3
bpo-39003: Make sure all test are the same when using -R in test_unparse (GH-17537) 2019-12-09 17:57:50 +00:00
Pablo Galindo 27fc3b6f3f
bpo-38870: Expose a function to unparse an ast object in the ast module (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.
2019-11-24 23:02:40 +00:00