summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ast.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.11] gh-95778: CVE-2020-10735: Prevent DoS by very large int() (#96500)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. This backports https://github.com/python/cpython/pull/96499 aka 511ca9452033ef95bc7d7fc404b8161068226002 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#).
* [3.11] gh-94996: Disallow lambda pos only params with feature_version < (3, ↵Shantanu2022-08-121-0/+7
| | | | | | | | | 8) (GH-95934) (GH-95936) (cherry picked from commit a965db37f27ffb232312bc13d9a509f0d93fcd20) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Automerge-Triggered-By: GH:lysnikolaou
* gh-94996: Disallow parsing pos only params with feature_version < (3, 8) ↵Miss Islington (bot)2022-08-121-1/+9
| | | | | | | (GH-94997) (cherry picked from commit b5e3ea286289fcad12be78480daf3756e350f69f) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* [3.11] gh-95185: Check recursion depth in the AST constructor (GH-95186) ↵Miss Islington (bot)2022-07-261-0/+21
| | | | | | | | (GH-95208) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> (cherry picked from commit 00474472944944b346d8409cfded84bb299f601a) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* gh-94949: Disallow parsing parenthesised ctx mgr with old feature_version ↵Miss Islington (bot)2022-07-181-0/+8
| | | | | | | | | | | | | | (GH-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> (cherry picked from commit 0daba822212cd5d6c63384a27f390f0945330c2b) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* gh-94947: Disallow parsing walrus with feature_version < (3, 8) (GH-94948)Miss Islington (bot)2022-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> (cherry picked from commit ae0be5a53bb4caee3de4888341addd9c94133f2d) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* Run Tools/scripts/reindent.py (GH-94225)Miss Islington (bot)2022-06-261-2/+2
| | | | | | | | Reindent files which were not properly formatted (PEP 8: 4 spaces). Remove also some trailing spaces. (cherry picked from commit e87ada48a9e5d9d03f9759138869216df0d7383a) Co-authored-by: Victor Stinner <vstinner@python.org>
* gh-92597: Ensure that AST nodes without explicit end positions can be ↵Miss Islington (bot)2022-05-311-0/+8
| | | | | | | compiled (GH-93359) (cherry picked from commit 705eaec28f7bee530b1c1635ba385a49a1feaf32) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* gh-93351: Ensure the position information in AST nodes created by the parser ↵Miss Islington (bot)2022-05-301-0/+27
| | | | | | | is always consistent (GH-93352) (cherry picked from commit 5893b5db98b38b17750c0572c7209774a5034898) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* 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>
* bpo-36290: Fix keytword collision handling in AST node constructors (GH-12382)Rémi Lapeyre2020-05-241-0/+9
|
* bpo-40662: Fixed ast.get_source_segment for ast nodes that have incomplete ↵Irit Katriel2020-05-181-0/+11
| | | | | location information (GH-20157) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-40528: Improve and clear several aspects of the ASDL definition code for ↵Batuhan Taskaya2020-05-061-1/+1
| | | | the AST (GH-19952)
* bpo-40355: Improve error messages in ast.literal_eval with malformed Dict ↵Curtis Bucher2020-05-051-0/+6
| | | | | nodes (GH-19868) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-40141: Include the value in the column position for keyword AST nodes ↵Pablo Galindo2020-04-031-1/+1
| | | | (GH-19348)
* bpo-40141: Add line and column information to ast.keyword nodes (GH-19283)Pablo Galindo2020-04-011-1/+1
|
* bpo-39999: Improve compatibility of the ast module. (GH-19056)Serhiy Storchaka2020-03-221-2/+2
| | | | | | | * 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-40000: Improve error messages when validating invalid ast.Constant nodes ↵Batuhan Taşkaya2020-03-191-0/+9
| | | | | (GH-19055) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-39638: Keep ASDL signatures in the AST nodes (GH-18515)Batuhan Taşkaya2020-03-161-0/+10
|
* bpo-34822: Simplify AST for subscription. (GH-9605)Serhiy Storchaka2020-03-101-10/+14
| | | | | | | | | * 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-14/+15
| | | | | | | 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: Implement a precedence algorithm in ast.unparse (GH-17377)Batuhan Taşkaya2020-03-011-1/+8
| | | | Implement a simple precedence algorithm for ast.unparse in order to avoid redundant parenthesis for nested structures in the final output.
* bpo-39474: Fix AST pos for expressions like (a)(b), (a)[b] and (a).b. (GH-18477)Serhiy Storchaka2020-02-121-0/+27
|
* bpo-39579: Fix Attribute end_col_offset to point at the current node (GH-18405)Lysandros Nikolaou2020-02-071-0/+8
|
* bpo-39235: Check end_lineno and end_col_offset of AST nodes. (GH-17926)Serhiy Storchaka2020-01-101-102/+104
|
* bpo-39158: ast.literal_eval() doesn't support empty sets (GH-17742)Raymond Hettinger2020-01-031-0/+1
|
* bpo-39080: Starred Expression's column offset fix when inside a CALL (GH-17645)Lysandros Nikolaou2019-12-181-0/+9
| | | | Co-Authored-By: Pablo Galindo <Pablogsal@gmail.com>
* Fix elif start column offset when there is an else following (GH-17596)Lysandros Nikolaou2019-12-141-0/+9
|
* bpo-39031: Include elif keyword when producing lineno/col-offset info for ↵Lysandros Nikolaou2019-12-121-0/+9
| | | | | | | | | | | | if_stmt (GH-17582) 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
* bpo-38535: Fix positions for AST nodes for calls without arguments in ↵Serhiy Storchaka2019-10-261-6/+6
| | | | decorators. (GH-16861)
* bpo-37995: Add an option to ast.dump() to produce a multiline output. (GH-15631)Serhiy Storchaka2019-09-091-0/+62
|