summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ast.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.12] gh-108416: Mark slow test methods with @requires_resource('cpu') ↵Miss Islington (bot)2023-09-021-0/+1
| | | | | | | | | | | | (GH-108421) (#108798) gh-108416: Mark slow test methods with @requires_resource('cpu') (GH-108421) Only mark tests which spend significant system or user time, by itself or in subprocesses. (cherry picked from commit f3ba0a74cd50274acdcd592d4ce8395b92492b7c) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.12] GH-107263: Increase C stack limit for most functions, except ↵Miss Islington (bot)2023-08-041-0/+1
| | | | | | | | | | `_PyEval_EvalFrameDefault()` (GH-107535) (#107618) GH-107263: Increase C stack limit for most functions, except `_PyEval_EvalFrameDefault()` (GH-107535) * Set C recursion limit to 1500, set cost of eval loop to 2 frames, and compiler mutliply to 2. (cherry picked from commit fa45958450aa3489607daf9855ca0474a2a20878) Co-authored-by: Mark Shannon <mark@hotpy.org>
* [3.12] GH-105588: Add missing error checks to some obj2ast_* converters ↵Miss Islington (bot)2023-06-151-0/+27
| | | | | | | | (GH-105838) GH-105588: Add missing error checks to some obj2ast_* converters (GH-105589) (cherry picked from commit a4056c8f9c2d9970d39e3cb6bffb255cd4b8a42c) Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
* [3.12] gh-104799: Default missing lists in AST to the empty list (GH-104834) ↵Miss Islington (bot)2023-06-021-0/+2
| | | | | | | | (#105213) (cherry picked from commit 77d25795862f19c6e3d647b76cfb10d5ce1f149c) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* [3.12] gh-104799: Move location of type_params AST fields (GH-104828) (#104974)Miss Islington (bot)2023-05-301-53/+77
| | | | | | | gh-104799: Move location of type_params AST fields (GH-104828) (cherry picked from commit ba73473f4c18ba4cf7ab18d84d94a47d2d37a0c5) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-103763: Implement PEP 695 (#103764)Jelle Zijlstra2023-05-161-43/+82
| | | | | | | | | | | | | | 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-104482: Fix error handling bugs in ast.c (#104483)Irit Katriel2023-05-151-0/+6
|
* gh-90953: Emit deprecation warnings for `ast` features deprecated in Python ↵Alex Waygood2023-05-061-127/+381
| | | | | | | 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-0/+11
|
* gh-102856: Initial implementation of PEP 701 (#102855)Pablo Galindo Salgado2023-04-191-5/+0
| | | | | | Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
* gh-101821: Test coverage for `ast.main` function (#101822)Nikita Sobolev2023-03-111-0/+20
|
* gh-101632: Add the new RETURN_CONST opcode (#101633)penguin_wwy2023-02-071-1/+1
|
* gh-101229: Add tests for aliases of imported names (#101230)Eclips42023-01-301-0/+18
|
* gh-100518: Add tests for `ast.NodeTransformer` (#100521)Nikita Sobolev2023-01-211-2/+126
|
* gh-100882: Improve `test_pickling` case in `test_ast.py` (#100883)Nikita Sobolev2023-01-091-12/+5
|
* test_ast uses infinite_recursion() to prevent crash (#100104)Victor Stinner2022-12-081-1/+2
| | | | | | | test.test_ast_recursion_limit() now uses infinite_recursion() of test.support to prevent crashes on debug builds. Before this change, the test crashed on ARM64 Windows 3.x buildbot worker which builds Python in debug mode.
* gh-99341: Cover type ignore nodes when incrementing line numbers (GH-99422)Batuhan Taskaya2022-11-221-0/+12
|
* GH-91079: Decouple C stack overflow checks from Python recursion checks. ↵Mark Shannon2022-10-051-3/+3
| | | | (GH-96510)
* gh-96670: Raise SyntaxError when parsing NULL bytes (#97594)Pablo Galindo Salgado2022-09-271-0/+4
|
* gh-96587: Raise `SyntaxError` for PEP654 on older `feature_version` (#96588)Nikita Sobolev2022-09-051-0/+9
|
* gh-95778: CVE-2020-10735: Prevent DoS by very large int() (#96499)Gregory P. Smith2022-09-021-0/+8
| | | | | | | | | | | | | | | | Integer to and from text conversions via CPython's bignum `int` type is not safe against denial of service attacks due to malicious input. Very large input strings with hundred thousands of digits can consume several CPU seconds. This PR comes fresh from a pile of work done in our private PSRT security response team repo. Signed-off-by: Christian Heimes [Red Hat] <christian@python.org> Tons-of-polishing-up-by: Gregory P. Smith [Google] <greg@krypto.org> Reviews via the private PSRT repo via many others (see the NEWS entry in the PR). <!-- gh-issue-number: gh-95778 --> * Issue: gh-95778 <!-- /gh-issue-number --> I wrote up [a one pager for the release managers](https://docs.google.com/document/d/1KjuF_aXlzPUxTK4BMgezGJ2Pn7uevfX7g0_mvgHlL7Y/edit#). Much of that text wound up in the Issue. Backports PRs already exist. See the issue for links.
* gh-94996: Disallow lambda pos only params with feature_version < (3, 8) ↵Shantanu2022-08-121-0/+7
| | | | (GH-95934)
* gh-94996: Disallow parsing pos only params with feature_version < (3, 8) ↵Shantanu2022-08-121-1/+9
| | | | (GH-94997)
* gh-95066: ast: Replace assert with ValueError (GH-95072)Shantanu2022-07-261-0/+6
| | | Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* gh-95185: Check recursion depth in the AST constructor (#95186)Pablo Galindo Salgado2022-07-241-0/+21
| | | Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-94949: Disallow parsing parenthesised ctx mgr with old feature_version ↵Shantanu2022-07-181-0/+8
| | | | | | | | | | | (#94950) * gh-94949: Disallow parsing parenthesised ctx manager with old feature_version * 📜🤖 Added by blurb_it. * Allow it with feature_version=(3, 9) as well Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* gh-94947: Disallow parsing walrus with feature_version < (3, 8) (#94948)Shantanu2022-07-181-0/+5
| | | | | | | | | * gh-94947: Disallow parsing walrus with feature_version < (3, 8) * oops, commit the parser * 📜🤖 Added by blurb_it. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
* Run Tools/scripts/reindent.py (#94225)Victor Stinner2022-06-261-2/+2
| | | | | Reindent files which were not properly formatted (PEP 8: 4 spaces). Remove also some trailing spaces.
* gh-92597: Ensure that AST nodes without explicit end positions can be ↵Pablo Galindo Salgado2022-05-311-0/+8
| | | | compiled (GH-93359)
* gh-93351: Ensure the position information in AST nodes created by the parser ↵Pablo Galindo Salgado2022-05-301-0/+27
| | | | is always consistent (GH-93352)
* bpo-43224: Implement PEP 646 grammar changes (GH-31018)Matthew Rahtz2022-03-261-1/+24
| | | Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* bpo-46091: Correctly calculate indentation levels for whitespace lines with ↵Pablo Galindo Salgado2022-01-251-2/+1
| | | | continuation characters (GH-30130)
* bpo-45292: [PEP-654] add except* (GH-29581)Irit Katriel2021-12-141-0/+23
|
* bpo-45408: Don't override previous tokenizer errors in the second parser ↵Pablo Galindo Salgado2021-10-071-0/+8
| | | | pass (GH-28812)
* bpo-43897: Reject "_" captures and top-level MatchStar in the AST validator ↵Brandt Bucher2021-07-291-1/+5
| | | | (GH-27432)
* bpo-43897: AST validation for pattern matching nodes (GH24771)Batuhan Taskaya2021-07-281-1/+142
|
* bpo-11105: reduce the recursion limit for tests (GH-26550)Batuhan Taskaya2021-06-081-2/+4
|
* bpo-11105: Do not crash when compiling recursive ASTs (GH-20594)Batuhan Taskaya2021-06-031-0/+14
| | | | | | | When compiling an AST object with a direct / indirect reference cycles, on the conversion phase because of exceeding amount of calls, a segfault was raised. This patch adds recursion guards to places for preventing user inputs to not to crash AST but instead raise a RecursionError.
* bpo-44142: drop redundant parantheses when unparsing tuples as assignment ↵Batuhan Taskaya2021-05-161-1/+2
| | | | targets (GH-26156)
* bpo-38659: [Enum] add _simple_enum decorator (GH-25497)Ethan Furman2021-04-211-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-30/+0
| | | This reverts commit dbac8f40e81eb0a29dc833e6409a1abf47467da6.
* bpo-38659: [Enum] add _simple_enum decorator (GH-25285)Ethan Furman2021-04-201-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-43798: Add source location attributes to alias (GH-25324)Matthew Suozzo2021-04-101-3/+25
| | | | | | | * Add source location attributes to alias. * Move alias star construction to pegen helper. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-42128: Structural Pattern Matching (PEP 634) (GH-22917)Brandt Bucher2021-02-261-0/+1
| | | | | 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-0/+12
| | | | messages (GH-23677)
* bpo-41887: omit leading spaces/tabs on ast.literal_eval (#22469)Batuhan Taskaya2020-10-041-0/+6
| | | Also document that eval() does this (the same way).
* bpo-41631: _ast module uses again a global state (#21961)Victor Stinner2020-09-151-0/+84
| | | | | | | | | | | | | | | | | 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-0/+11
|
* bpo-40870: Invalidate usage of some constants with ast.Name (GH-20649)Batuhan Taskaya2020-06-061-0/+7
|
* bpo-40614: Respect feature version for f-string debug expressions (GH-20196)Shantanu2020-05-271-0/+5
| | | | Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>