summaryrefslogtreecommitdiffstats
path: root/Lib/ast.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-92671: Don't omit parentheses when unparsing empty tuples (GH-92673)Batuhan Taskaya2022-05-161-1/+5
|
* bpo-43224: Implement PEP 646 grammar changes (GH-31018)Matthew Rahtz2022-03-261-6/+3
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-45292: [PEP-654] add except* (GH-29581)Irit Katriel2021-12-141-2/+19
|
* Fix typos in multiple files (GH-26689)Binbin2021-06-131-1/+1
| | | Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-44142: drop redundant parantheses when unparsing tuples as assignment ↵Batuhan Taskaya2021-05-161-3/+6
| | | | targets (GH-26156)
* bpo-44081: improve ast.unparse() for lambdas with no parameters (GH-26000)Batuhan Taskaya2021-05-151-5/+8
|
* bpo-43417: Better buffer handling for ast.unparse (GH-24772)Batuhan Taskaya2021-05-081-57/+59
|
* Fix typo in ast.py (GH-25740)Ikko Ashimine2021-05-041-2/+2
| | | parantheses -> parentheses
* bpo-43892: Make match patterns explicit in the AST (GH-25585)Nick Coghlan2021-04-291-4/+75
| | | Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
* bpo-38659: [Enum] add _simple_enum decorator (GH-25497)Ethan Furman2021-04-211-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add: * `_simple_enum` decorator to transform a normal class into an enum * `_test_simple_enum` function to compare * `_old_convert_` to enable checking `_convert_` generated enums `_simple_enum` takes a normal class and converts it into an enum: @simple_enum(Enum) class Color: RED = 1 GREEN = 2 BLUE = 3 `_old_convert_` works much like` _convert_` does, using the original logic: # in a test file import socket, enum CheckedAddressFamily = enum._old_convert_( enum.IntEnum, 'AddressFamily', 'socket', lambda C: C.isupper() and C.startswith('AF_'), source=_socket, ) `_test_simple_enum` takes a traditional enum and a simple enum and compares the two: # in the REPL or the same module as Color class CheckedColor(Enum): RED = 1 GREEN = 2 BLUE = 3 _test_simple_enum(CheckedColor, Color) _test_simple_enum(CheckedAddressFamily, socket.AddressFamily) Any important differences will raise a TypeError
* Revert "bpo-38659: [Enum] add _simple_enum decorator (GH-25285)" (GH-25476)Ethan Furman2021-04-201-3/+2
| | | This reverts commit dbac8f40e81eb0a29dc833e6409a1abf47467da6.
* bpo-38659: [Enum] add _simple_enum decorator (GH-25285)Ethan Furman2021-04-201-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | add: _simple_enum decorator to transform a normal class into an enum _test_simple_enum function to compare _old_convert_ to enable checking _convert_ generated enums _simple_enum takes a normal class and converts it into an enum: @simple_enum(Enum) class Color: RED = 1 GREEN = 2 BLUE = 3 _old_convert_ works much like _convert_ does, using the original logic: # in a test file import socket, enum CheckedAddressFamily = enum._old_convert_( enum.IntEnum, 'AddressFamily', 'socket', lambda C: C.isupper() and C.startswith('AF_'), source=_socket, ) test_simple_enum takes a traditional enum and a simple enum and compares the two: # in the REPL or the same module as Color class CheckedColor(Enum): RED = 1 GREEN = 2 BLUE = 3 _test_simple_enum(CheckedColor, Color) _test_simple_enum(CheckedAddressFamily, socket.AddressFamily) Any important differences will raise a TypeError
* bpo-43521: Allow ast.unparse with empty sets and NaN (GH-24897)Kodi Arfer2021-03-181-6/+14
| | | Automerge-Triggered-By: GH:pablogsal
* bpo-42128: Structural Pattern Matching (PEP 634) (GH-22917)Brandt Bucher2021-02-261-0/+27
| | | | | Co-authored-by: Guido van Rossum <guido@python.org> Co-authored-by: Talin <viridia@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* bpo-28964: add line number of node (if available) to ast.literal_eval error ↵Irit Katriel2020-12-251-1/+4
| | | | messages (GH-23677)
* bpo-28002: Roundtrip f-strings with ast.unparse better (#19612)Shantanu2020-11-201-24/+86
| | | | | | | | | 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>
* bpo-41887: omit leading spaces/tabs on ast.literal_eval (#22469)Batuhan Taskaya2020-10-041-1/+1
| | | Also document that eval() does this (the same way).
* bpo-41631: _ast module uses again a global state (#21961)Victor Stinner2020-09-151-15/+22
| | | | | | | | | | | | | | | | | 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.
* bpo-40726: handle uninitalized end_lineno on ast.increment_lineno (GH-20312)Batuhan Taskaya2020-08-051-3/+10
|
* 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
|