summaryrefslogtreecommitdiffstats
path: root/Lib/ast.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-110259: Fix f-strings with multiline expressions and format specs (#110271)Pablo Galindo Salgado2023-10-051-3/+8
| | | Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
* gh-108843: fix ast.unparse for f-string with many quotes (#108981)Shantanu2023-09-181-1/+20
|
* gh-108469: Update ast.unparse for unescaped quote support from PEP701 [3.12] ↵Anthony Shaw2023-09-051-21/+10
| | | | | | (#108553) Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
* gh-108113: Make it possible to create an optimized AST (#108154)Irit Katriel2023-08-211-2/+4
|
* gh-104799: PEP 695 backward compatibility for ast.unparse (#105846)Jelle Zijlstra2023-06-161-2/+4
|
* gh-104656: Rename typeparams AST node to type_params (#104657)Jelle Zijlstra2023-05-221-6/+6
|
* gh-103763: Implement PEP 695 (#103764)Jelle Zijlstra2023-05-161-0/+26
| | | | | | | | | | | | | | This implements PEP 695, Type Parameter Syntax. It adds support for: - Generic functions (def func[T](): ...) - Generic classes (class X[T](): ...) - Type aliases (type X = ...) - New scoping when the new syntax is used within a class body - Compiler and interpreter changes to support the new syntax and scoping rules Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: Eric Traut <eric@traut.com> Co-authored-by: Larry Hastings <larry@hastings.org> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-90953: Emit deprecation warnings for `ast` features deprecated in Python ↵Alex Waygood2023-05-061-8/+74
| | | | | | | 3.8 (#104199) `ast.Num`, `ast.Str`, `ast.Bytes`, `ast.Ellipsis` and `ast.NameConstant` now all emit deprecation warnings on import, access, instantation or `isinstance()` checks. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-103285: Rewrite _splitlines_no_ff to improve performance (#103307)Tian Gao2023-04-241-18/+8
|
* gh-99341: Cover type ignore nodes when incrementing line numbers (GH-99422)Batuhan Taskaya2022-11-221-0/+6
|
* gh-95588: Drop the safety claim from `ast.literal_eval` docs. (#95919)Gregory P. Smith2022-10-021-1/+3
| | | It was never really safe and this claim conflicts directly with the big warning in the docs about it being able to crash the interpreter.
* gh-92986: Fix ast.unparse when ImportFrom.level is None (#92992)Shantanu2022-09-051-1/+1
| | | | | 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)
* ast.parse: check `feature_version` common case first (GH-94640)Anthony Sottile2022-08-291-3/+3
|
* gh-95066: ast: Replace assert with ValueError (GH-95072)Shantanu2022-07-261-1/+2
| | | Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* 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
|