Serhiy Storchaka
bc3fa17c30
gh-82312: Further improvement of error messages for generating AST nodes (GH-150912)
...
This is a follow up of GH-17715.
* Use %T instead of _PyType_Name().
* Add the wrong type name we got for identifier and string.
2026-06-30 01:03:33 +03:00
Batuhan Taskaya
3ff2117ea3
bpo-38131: Improve messages when generating AST nodes from objects with wrong field values (GH-17715)
2026-06-04 10:58:51 +00:00
bdedc4a20e
gh-116021: Deprecate support for instantiating abstract AST nodes ( #137865 )
...
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com >
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com >
2026-05-02 09:50:06 -07:00
d2f506ae07
gh-137600: Promote ast node constructor deprecation warnings to errors ( #137601 )
...
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com >
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com >
2026-04-28 02:51:06 +00:00
Karolina Surma and Victor Stinner
1887a95f51
gh-128341: Use _Py_ABI_SLOT in stdlib modules ( #145770 )
...
Rename from _Py_INTERNAL_ABI_SLOT to _Py_ABI_SLOT
and define the macro using _PyABIInfo_DEFAULT.
Use the ABI slot in stdlib extension modules to enable running
a check of ABI version compatibility.
_tkinter, _tracemalloc and readline don't use the slots, hence they need
explicit handling.
Co-authored-by: Victor Stinner <vstinner@python.org >
2026-03-24 17:47:55 +00:00
46d5106cfa
gh-142349: Implement PEP 810 - Explicit lazy imports ( #142351 )
...
Co-authored-by: T. Wouters <twouters@meta.com >
Co-authored-by: Brittany Reynoso <breynoso@meta.com >
Co-authored-by: Dino Viehland <dinoviehland@meta.com >
2026-02-12 00:15:33 +00:00
adam j hartz and Jelle Zijlstra
ccbe41e27c
gh-143055: Implementation of PEP 798 ( #143056 )
...
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com >
2026-01-30 20:37:52 -08:00
Jelle Zijlstra and Victor Stinner
639c1ad4f1
gh-144169: Fix three crashes in AST objects with non-str kwargs ( #144178 )
...
Co-authored-by: Victor Stinner <vstinner@python.org >
2026-01-25 17:28:58 -08:00
Samuel
f37f57dfe6
gh-131421: Fix ASDL kw_defaults being expr* instead of expr?* (GH-133773)
...
Also fix docs ASDL highlighting.
2025-12-29 13:43:09 +02:00
Stan Ulbrych
95953b692d
gh-140471: Fix buffer overflow in AST node initialization with malformed _fields ( #140506 )
2025-10-23 15:35:21 +00:00
f49a07b531
gh-133968: Add PyUnicodeWriter_WriteASCII() function ( #133973 )
...
Replace most PyUnicodeWriter_WriteUTF8() calls with
PyUnicodeWriter_WriteASCII().
Unrelated change to please the linter: remove an unused
import in test_ctypes.
Co-authored-by: Peter Bierma <zintensitydev@gmail.com >
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com >
2025-05-29 14:54:30 +00:00
Jelle Zijlstra
7dddb4e667
gh-133783: Fix __replace__ on AST nodes for optional attributes ( #133797 )
2025-05-10 09:17:38 -07:00
30840706b0
gh-131421: fix ASDL grammar for Dict to have an expr?* keys field ( #131419 )
...
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 >
2025-05-04 16:03:38 -07:00
60202609a2
gh-132661: Implement PEP 750 ( #132662 )
...
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 >
2025-04-30 11:46:41 +02:00
Victor Stinner
978e37bb5f
gh-131238: Add explicit includes to pycore headers ( #131257 )
2025-03-17 12:32:43 +01:00
Mark Shannon
014223649c
GH-130396: Use computed stack limits on linux (GH-130398)
...
* 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
2025-02-25 09:24:48 +00:00
Petr Viktorin
ef29104f7d
GH-91079: Revert "GH-91079: Implement C stack limits using addresses, not 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 2498c22fa0 .
2025-02-24 11:16:08 +01:00
Mark Shannon
2498c22fa0
GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)
...
* 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
2025-02-19 11:44:57 +00:00
Irit Katriel
c9b1bf302c
gh-130139: always check ast node type in ast.parse() with ast input ( #130140 )
2025-02-16 13:32:39 +00:00
Victor Stinner
0093a31273
gh-119182: Use public PyUnicodeWriter in Python-ast.c ( #129209 )
...
Replace the private _PyUnicodeWriter API with the public
PyUnicodeWriter API.
Use PyUnicodeWriter_WriteRepr() in ast_repr_list().
2025-01-23 00:57:37 +00:00
sobolevn
b2eaa75b17
gh-126105: Fix crash in ast module, when ._fields is deleted ( #126115 )
...
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).
2024-10-29 17:42:48 +02:00
Sam Gross
427dcf24de
gh-125268: Use static string for "1e309" in AST ( #125272 )
...
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.
2024-10-10 16:21:29 -04:00
Tomas R.
a1be83dae3
gh-125010: Fix use-after-free in AST repr() ( #125015 )
2024-10-06 12:46:03 -07:00
Victor Stinner
6c7d5c6415
gh-111178: Fix function signatures in Python-ast.c ( #124942 )
2024-10-04 11:59:08 +02:00
21d2a9ab2f
gh-116022: Improve repr() of AST nodes ( #117046 )
...
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 >
2024-09-18 10:28:22 -07:00
Jelle Zijlstra
58e8cf2bb6
gh-121332: Make AST node constructor check _attributes instead of hardcoding attributes ( #121334 )
2024-07-11 14:34:53 +00:00
Bénédikt Tran
9728ead361
gh-121141: add support for copy.replace to AST nodes ( #121162 )
2024-07-03 20:10:54 -07:00
Jelle Zijlstra
42b2c9d78d
gh-120108: Fix deepcopying of AST trees with .parent attributes ( #120114 )
2024-06-25 08:12:11 -07:00
Jelle Zijlstra and Alex Waygood
68fbc00dc8
gh-118851: Default ctx arguments to AST constructors to Load() ( #118854 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com >
2024-05-09 15:30:14 -07:00
Jelle Zijlstra
e0422198fb
gh-117486: Improve behavior for user-defined AST subclasses ( #118212 )
...
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.
2024-05-06 15:57:27 -07:00
Brett Simmers
c2627d6eea
gh-116322: Add Py_mod_gil module slot ( #116882 )
...
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).
2024-05-03 11:30:55 -04:00
ca269e58c2
gh-116126: Implement PEP 696 ( #116129 )
...
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 >
2024-05-03 06:17:32 -07:00
Jelle Zijlstra
4c71d51a4b
gh-117266: Fix crashes on user-created AST subclasses (GH-117276)
...
Fix crashes on user-created AST subclasses
2024-03-28 11:30:31 +01:00
Serhiy Storchaka
72d3cc94cd
gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438)
2024-03-07 11:21:08 +02:00
Jelle Zijlstra
ed4dfd8825
gh-105858: Improve AST node constructors ( #105880 )
...
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>
2024-02-27 18:13:03 -08:00
Mark Shannon
17b73ab99e
GH-113655: Lower the C recursion limit on various platforms (GH-113944)
2024-01-16 09:32:01 +00:00
Yilei Yang and Gregory P. Smith [Google LLC]
48c49739f5
gh-106905: Use separate structs to track recursion depth in each PyAST_mod2obj call. (GH-113035)
...
Co-authored-by: Gregory P. Smith [Google LLC] <greg@krypto.org >
2023-12-25 19:36:59 +02:00
Sam Gross
446f18a911
gh-111956: Add thread-safe one-time initialization. (gh-111960)
2023-11-16 12:19:54 -07:00
1447af7970
gh-106905: avoid incorrect SystemError about recursion depth mismatch ( #106906 )
...
* 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 >
2023-11-13 13:05:17 +00:00
Victor Stinner
b0edf3b98e
GH-91079: Rename C_RECURSION_LIMIT to Py_C_RECURSION_LIMIT ( #108507 )
...
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.
2023-09-08 09:48:28 +00:00
Victor Stinner
e59a95238b
gh-108444: Remove _PyLong_AsInt() function ( #108461 )
...
* Update Parser/asdl_c.py to regenerate Python/Python-ast.c.
* Remove _PyLong_AsInt() alias to PyLong_AsInt().
2023-08-25 11:13:59 +02:00
Irit Katriel
10a91d7e98
gh-108113: Make it possible to create an optimized AST ( #108154 )
2023-08-21 16:31:30 +00:00
Mark Shannon
fa45958450
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.
2023-08-04 10:10:29 +01:00
Victor Stinner
1a3faba9f1
gh-106869: Use new PyMemberDef constant names ( #106871 )
...
* 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)
2023-07-25 15:28:30 +02:00
Serhiy Storchaka
be1b968dc1
gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)
2023-07-12 08:57:10 +03:00
Nikita Sobolev
46c1097868
gh-106145: Make end_{lineno,col_offset} required on type_param nodes ( #106224 )
2023-06-30 23:45:08 +00:00
Brandt Bucher
a4056c8f9c
GH-105588: Add missing error checks to some obj2ast_* converters (GH-105589)
2023-06-15 15:45:13 -07:00
Jelle Zijlstra and Alex Waygood
77d2579586
gh-104799: Default missing lists in AST to the empty list ( #104834 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com >
2023-06-01 18:39:39 -07:00
Jelle Zijlstra and Alex Waygood
ba73473f4c
gh-104799: Move location of type_params AST fields ( #104828 )
...
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com >
2023-05-26 05:54:37 -07:00
Jelle Zijlstra
a5f244d627
gh-104656: Rename typeparams AST node to type_params ( #104657 )
2023-05-21 21:25:09 -07:00