aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/Python-ast.c
Commit message (Collapse)AuthorAge
* gh-131421: fix ASDL grammar for `Dict` to have an `expr?*` keys field (#131419)Samuel2025-05-04
| | | | | | | | | | | | | In the `ast` documentation for Python: * https://docs.python.org/3/library/ast.html#ast.Dict it is made clear that: > When doing dictionary unpacking using dictionary literals the expression to be expanded goes in the values list, with a `None` at the corresponding position in `keys`. Hence, `keys` is really a `expr?*` and *not* a `expr*`. Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* gh-132661: Implement PEP 750 (#132662)Lysandros Nikolaou2025-04-30
| | | | | | | | | | | | | Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Wingy <git@wingysam.xyz> Co-authored-by: Koudai Aono <koxudaxi@gmail.com> Co-authored-by: Dave Peck <davepeck@gmail.com> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Paul Everitt <pauleveritt@me.com> Co-authored-by: sobolevn <mail@sobolevn.me>
* gh-131238: Add explicit includes to pycore headers (#131257)Victor Stinner2025-03-17
|
* GH-130396: Use computed stack limits on linux (GH-130398)Mark Shannon2025-02-25
| | | | | | | | | | | * Implement C recursion protection with limit pointers for Linux, MacOS and Windows * Remove calls to PyOS_CheckStack * Add stack protection to parser * Make tests more robust to low stacks * Improve error messages for stack overflow
* GH-91079: Revert "GH-91079: Implement C stack limits using addresses, not ↵Petr Viktorin2025-02-24
| | | | | | | | | counters. (GH-130007)" for now (GH130413) Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now Unfortunatlely, the change broke some buildbots. This reverts commit 2498c22fa0a2b560491bc503fa676585c1a603d0.
* GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)Mark Shannon2025-02-19
| | | | | | | | | | | | * Implement C recursion protection with limit pointers * Remove calls to PyOS_CheckStack * Add stack protection to parser * Make tests more robust to low stacks * Improve error messages for stack overflow
* gh-130139: always check ast node type in ast.parse() with ast input (#130140)Irit Katriel2025-02-16
|
* gh-119182: Use public PyUnicodeWriter in Python-ast.c (#129209)Victor Stinner2025-01-23
| | | | | | Replace the private _PyUnicodeWriter API with the public PyUnicodeWriter API. Use PyUnicodeWriter_WriteRepr() in ast_repr_list().
* gh-126105: Fix crash in `ast` module, when `._fields` is deleted (#126115)sobolevn2024-10-29
| | | | Previously, if the `ast.AST._fields` attribute was deleted, attempts to create a new `as`t node would crash due to the assumption that `_fields` always had a non-NULL value. Now it has been fixed by adding an extra check to ensure that `_fields` does not have a NULL value (this can happen when you manually remove `_fields` attribute).
* gh-125268: Use static string for "1e309" in AST (#125272)Sam Gross2024-10-10
| | | | | When formatting the AST as a string, infinite values are replaced by 1e309, which evaluates to infinity. The initialization of this string replacement was not thread-safe in the free threading build.
* gh-125010: Fix `use-after-free` in AST `repr()` (#125015)Tomas R.2024-10-06
|
* gh-111178: Fix function signatures in Python-ast.c (#124942)Victor Stinner2024-10-04
|
* gh-116022: Improve `repr()` of AST nodes (#117046)Tomas R2024-09-18
| | | | | | Co-authored-by: AN Long <aisk@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* gh-121332: Make AST node constructor check _attributes instead of hardcoding ↵Jelle Zijlstra2024-07-11
| | | | attributes (#121334)
* gh-121141: add support for `copy.replace` to AST nodes (#121162)Bénédikt Tran2024-07-03
|
* gh-120108: Fix deepcopying of AST trees with .parent attributes (#120114)Jelle Zijlstra2024-06-25
|
* gh-118851: Default ctx arguments to AST constructors to Load() (#118854)Jelle Zijlstra2024-05-09
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-117486: Improve behavior for user-defined AST subclasses (#118212)Jelle Zijlstra2024-05-06
| | | | | | | | Now, such classes will no longer require changes in Python 3.13 in the normal case. The test suite for robotframework passes with no DeprecationWarnings under this PR. I also added a new DeprecationWarning for the case where `_field_types` exists but is incomplete, since that seems likely to indicate a user mistake.
* gh-116322: Add Py_mod_gil module slot (#116882)Brett Simmers2024-05-03
| | | | | | | | | | | | | | This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL. PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148. A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If `-v` is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).
* gh-116126: Implement PEP 696 (#116129)Jelle Zijlstra2024-05-03
| | | | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* gh-117266: Fix crashes on user-created AST subclasses (GH-117276)Jelle Zijlstra2024-03-28
| | | Fix crashes on user-created AST subclasses
* gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438)Serhiy Storchaka2024-03-07
|
* gh-105858: Improve AST node constructors (#105880)Jelle Zijlstra2024-02-27
| | | | | | | | | | | | | | | | | Demonstration: >>> ast.FunctionDef.__annotations__ {'name': <class 'str'>, 'args': <class 'ast.arguments'>, 'body': list[ast.stmt], 'decorator_list': list[ast.expr], 'returns': ast.expr | None, 'type_comment': str | None, 'type_params': list[ast.type_param]} >>> ast.FunctionDef() <stdin>:1: DeprecationWarning: FunctionDef.__init__ missing 1 required positional argument: 'name'. This will become an error in Python 3.15. <stdin>:1: DeprecationWarning: FunctionDef.__init__ missing 1 required positional argument: 'args'. This will become an error in Python 3.15. <ast.FunctionDef object at 0x101959460> >>> node = ast.FunctionDef(name="foo", args=ast.arguments()) >>> node.decorator_list [] >>> ast.FunctionDef(whatever="you want", name="x", args=ast.arguments()) <stdin>:1: DeprecationWarning: FunctionDef.__init__ got an unexpected keyword argument 'whatever'. Support for arbitrary keyword arguments is deprecated and will be removed in Python 3.15. <ast.FunctionDef object at 0x1019581f0>
* GH-113655: Lower the C recursion limit on various platforms (GH-113944)Mark Shannon2024-01-16
|
* gh-106905: Use separate structs to track recursion depth in each ↵Yilei Yang2023-12-25
| | | | | | PyAST_mod2obj call. (GH-113035) Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org>
* gh-111956: Add thread-safe one-time initialization. (gh-111960)Sam Gross2023-11-16
|
* gh-106905: avoid incorrect SystemError about recursion depth mismatch (#106906)Markus Mohrhard2023-11-13
| | | | | | | | | | * gh-106905: avoid incorrect SystemError about recursion depth mismatch * Update Misc/NEWS.d/next/Core and Builtins/2023-07-20-11-41-16.gh-issue-106905.AyZpuB.rst --------- Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* GH-91079: Rename C_RECURSION_LIMIT to Py_C_RECURSION_LIMIT (#108507)Victor Stinner2023-09-08
| | | | | | | Symbols of the C API should be prefixed by "Py_" to avoid conflict with existing names in 3rd party C extensions on "#include <Python.h>". test.pythoninfo now logs Py_C_RECURSION_LIMIT constant and other _testcapi and _testinternalcapi constants.
* gh-108444: Remove _PyLong_AsInt() function (#108461)Victor Stinner2023-08-25
| | | | * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Remove _PyLong_AsInt() alias to PyLong_AsInt().
* gh-108113: Make it possible to create an optimized AST (#108154)Irit Katriel2023-08-21
|
* GH-107263: Increase C stack limit for most functions, except ↵Mark Shannon2023-08-04
| | | | | | `_PyEval_EvalFrameDefault()` (GH-107535) * Set C recursion limit to 1500, set cost of eval loop to 2 frames, and compiler mutliply to 2.
* gh-106869: Use new PyMemberDef constant names (#106871)Victor Stinner2023-07-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove '#include "structmember.h"'. * If needed, add <stddef.h> to get offsetof() function. * Update Parser/asdl_c.py to regenerate Python/Python-ast.c. * Replace: * T_SHORT => Py_T_SHORT * T_INT => Py_T_INT * T_LONG => Py_T_LONG * T_FLOAT => Py_T_FLOAT * T_DOUBLE => Py_T_DOUBLE * T_STRING => Py_T_STRING * T_OBJECT => _Py_T_OBJECT * T_CHAR => Py_T_CHAR * T_BYTE => Py_T_BYTE * T_UBYTE => Py_T_UBYTE * T_USHORT => Py_T_USHORT * T_UINT => Py_T_UINT * T_ULONG => Py_T_ULONG * T_STRING_INPLACE => Py_T_STRING_INPLACE * T_BOOL => Py_T_BOOL * T_OBJECT_EX => Py_T_OBJECT_EX * T_LONGLONG => Py_T_LONGLONG * T_ULONGLONG => Py_T_ULONGLONG * T_PYSSIZET => Py_T_PYSSIZET * T_NONE => _Py_T_NONE * READONLY => Py_READONLY * PY_AUDIT_READ => Py_AUDIT_READ * READ_RESTRICTED => Py_AUDIT_READ * PY_WRITE_RESTRICTED => _Py_WRITE_RESTRICTED * RESTRICTED => (READ_RESTRICTED | _Py_WRITE_RESTRICTED)
* gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)Serhiy Storchaka2023-07-12
|
* gh-106145: Make `end_{lineno,col_offset}` required on `type_param` nodes ↵Nikita Sobolev2023-06-30
| | | | (#106224)
* GH-105588: Add missing error checks to some obj2ast_* converters (GH-105589)Brandt Bucher2023-06-15
|
* gh-104799: Default missing lists in AST to the empty list (#104834)Jelle Zijlstra2023-06-01
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-104799: Move location of type_params AST fields (#104828)Jelle Zijlstra2023-05-26
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-104656: Rename typeparams AST node to type_params (#104657)Jelle Zijlstra2023-05-21
|
* gh-103763: Implement PEP 695 (#103764)Jelle Zijlstra2023-05-15
| | | | | | | | | | | | | | 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-99113: Add Py_MOD_PER_INTERPRETER_GIL_SUPPORTED (gh-104205)Eric Snow2023-05-05
| | | Here we are doing no more than adding the value for Py_mod_multiple_interpreters and using it for stdlib modules. We will start checking for it in gh-104206 (once PyInterpreterState.ceval.own_gil is added in gh-104204).
* gh-100227: Move _str_replace_inf to PyInterpreterState (gh-102333)Eric Snow2023-02-28
| | | https://github.com/python/cpython/issues/100227
* gh-99300: Use Py_NewRef() in Python/Python-ast.c (#99499)Victor Stinner2022-11-15
| | | | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in Python/Python-ast.c. Update Parser/asdl_c.py to regenerate code.
* gh-81057: Move Global Variables Holding Objects to _PyRuntimeState. (gh-99487)Eric Snow2022-11-14
| | | | | This moves nearly all remaining object-holding globals in core code (other than static types). https://github.com/python/cpython/issues/81057
* gh-99300: Use Py_NewRef() in Python/ directory (#99317)Victor Stinner2022-11-10
| | | | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Python/ directory. Update Parser/asdl_c.py to regenerate Python/Python-ast.c.
* GH-91079: Decouple C stack overflow checks from Python recursion checks. ↵Mark Shannon2022-10-05
| | | | (GH-96510)
* gh-95185: Check recursion depth in the AST constructor (#95186)Pablo Galindo Salgado2022-07-24
| | | Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-92597: Ensure that AST nodes without explicit end positions can be ↵Pablo Galindo Salgado2022-06-01
| | | | compiled (GH-93359)
* Use static inline function Py_EnterRecursiveCall() (#91988)Victor Stinner2022-05-04
| | | | | | | | | | | | | | | | Currently, calling Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() may use a function call or a static inline function call, depending if the internal pycore_ceval.h header file is included or not. Use a different name for the static inline function to ensure that the static inline function is always used in Python internals for best performance. Similar approach than PyThreadState_GET() (function call) and _PyThreadState_GET() (static inline function). * Rename _Py_EnterRecursiveCall() to _Py_EnterRecursiveCallTstate() * Rename _Py_LeaveRecursiveCall() to _Py_LeaveRecursiveCallTstate() * pycore_ceval.h: Rename Py_EnterRecursiveCall() to _Py_EnterRecursiveCall() and Py_LeaveRecursiveCall() and _Py_LeaveRecursiveCall()
* bpo-46289: Make conversion of FormattedValue not optional on ASDL (GH-30467)Batuhan Taskaya2022-01-07
| | | Automerge-Triggered-By: GH:isidentical
* bpo-45292: [PEP-654] add except* (GH-29581)Irit Katriel2021-12-14
|