Commit Graph
1390 Commits
Author SHA1 Message Date
Pablo Galindo Salgado 0d6671d744 gh-153568: Skip newline translation for source without carriage returns (#153584)
The tokenizer copied every input byte by byte to normalize newlines,
but source without a carriage return needs no translation and can be
copied verbatim.
2026-09-14 16:24:02 +00:00
Pablo Galindo Salgado f88d6687b6 gh-153568: Make the parser's per-rule stack check an inline comparison (#153573)
* gh-153568: Make the parser's per-rule stack check an inline comparison

The parser now caches the thread state and stack limit up front and
only falls back to the full check when the stack is nearly exhausted.

* fixup! gh-153568: Make the parser's per-rule stack check an inline comparison

* fixup! gh-153568: Make the parser's per-rule stack check an inline comparison
2026-09-14 16:08:59 +00:00
Pablo Galindo Salgado ac86e12d74 gh-153568: Stop re-walking memo lists when growing left-recursive rules (#153574)
The left-recursion driver now keeps a direct reference to its memo
entry and updates it in place on every iteration.
2026-09-14 11:41:14 -04:00
Shamil e66bec09b7 gh-157378: Fix SyntaxError.offset for "Non-UTF-8 code" error (#157412) 2026-09-14 12:13:40 +00:00
Bartosz Sławecki b62380fdb8 gh-156021: Don't include ... for empty AST node representations (GH-156022) 2026-09-14 14:06:22 +02:00
Pengyu Lee 1a703ab9e6 gh-154719: Preserve trailing whitespace in t-string interpolation expressions (#154762) 2026-09-13 01:09:22 +01:00
Pablo Galindo Salgado 7bfa97f4dc gh-153569: hide tokenizer state behind token and source operations (#156654)
Make pegen and _tokenize consume tokenizer operations instead of accessing the tokenizer layout. Return token kind, span, location, and raw-string context together, so parser actions use the context of the cached token.

Represent persistent scanner positions as offsets and remove pointer save/restore bookkeeping when input storage grows.
2026-09-12 14:30:00 +01:00
Pablo Galindo Salgado 2ddc218b20 gh-153569: centralize formatted-string state and source spans (#156484)
Formatted-string expressions and comments can outlive the buffer window where
scanning began. Pointer boundaries require buffer relocation to repair tokenizer
state. Record logical source ranges instead. Retain the active input window while a
formatted string is open, give each mode ownership of its comment spans, and
materialize text through shared span views.
2026-09-09 00:15:01 +01:00
Pablo Galindo Salgado 09117bc317 gh-153569: return token spans and unify decoded source storage (#156482)
Represent token boundaries as logical source offsets with explicit start
and end locations, and adapt pegen and _tokenize to consume them.

Use SourceText to own decoded input across all reader modes. Streaming
readers discard consumed windows while preserving logical offsets and
reusing the allocation. Prepared and interactive input retain their source.

Force source relocation on growth in debug builds and add coverage for
formatted-string growth, interactive input, storage reuse, and offset
limits. Scanner positions remain pointers, rebased when storage moves.
2026-09-06 21:15:44 +01:00
Serhiy StorchakaandClaude Opus 5 59a691361c gh-156894: Fix the position of syntax errors which cover a range (GH-156901)
The callers of _PyTokenizer_syntaxerror_known_range() pass columns in bytes,
but SyntaxError.offset and end_offset are columns in characters.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-04 14:14:13 +03:00
Stan Ulbrych d7f9c6400f gh-156689: Fix out-of-bounds read in PyAst_CheckMode() for mode='func_type' (#156697) 2026-08-31 12:49:03 +01:00
c922aa0ddd gh-72353: Continue reading from the console after ignored Ctrl+C (GH-155434)
If the console cancels a read because of Ctrl+C, but the SIGINT handler
does not raise an exception, restart the read instead of ending it as if
at end of file.

Co-authored-by: Valeriya Sinevich <valeriya.sinevich@phystech.edu>
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
2026-08-29 21:05:33 +03:00
Pablo Galindo Salgado f5dbcbafae gh-153569: Unify tokenizer input readers (#156472) 2026-08-28 17:26:05 +02:00
Pablo Galindo Salgado f54fd2ab6e gh-153569: Add tokenizer source and cursor primitives (#153587) 2026-08-26 12:38:22 +01:00
Victor Stinner 079dd5ee39 gh-155742: Get PyBytes_AS_STRING() as const char* (#155751)
Use "const char*" type instead of "char*" to store
PyBytes_AS_STRING(): treat bytes objects as immutable.
2026-08-14 12:00:45 +00:00
Petr ViktorinandBartosz Sławecki a85830c7f8 gh-154775: Don't accept duplicate plus sign when matching complex number (GH-154776)
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2026-07-28 09:19:46 +02:00
Pablo Galindo Salgado d49e76b1eb gh-153568: Skip parser memo lookups that cannot match (#153571)
Each token now carries a small filter of the rule types present in its
memo list, so the common case of a miss no longer walks the list.
2026-07-18 18:12:38 +02:00
Pablo Galindo Salgado a0c6c4cc35 gh-153568: Cache repeated identifiers while parsing (#153577) 2026-07-18 13:25:39 +00:00
Pablo Galindo Salgado a2d3787105 gh-153569: Split tokenizer lexer into focused files (#153585) 2026-07-11 19:53:27 +01:00
Serhiy StorchakaandClaude Fable 5 1034e73f69 gh-153171: Produce specialized syntax errors for 'not' after an operator in more positions (GH-153175)
Move the invalid_factor rule from term to factor and the
invalid_arithmetic rule from shift_expr to sum, so that they are
tried at all positions where the invalid construct can occur.
Previously a generic "invalid syntax" error was reported for
constructs like "1 << 2 + not x" or "1 * + not x".

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-06 13:00:05 +03:00
sobolevn ec5f154e33 gh-150459: Fix SyntaxError message for from x lazy import y (#150877) 2026-07-04 14:17:58 +01:00
tonghuaroot (童话) 669299b62f gh-151763: Fix OOM-0013 crash when the parser or compiler fails to allocate (#151968) 2026-07-02 01:34:16 +01:00
Thomas Kowalski 2dd6e59aea gh-149689: add missing error checks in Parser/action_helpers.c (#149710) 2026-06-29 23:18:19 +00:00
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
Aniket 0f501b9b74 gh-146495: Improve SyntaxError message for && and || operators (#150906) 2026-06-27 18:57:10 +02:00
Bartosz Sławecki f1a5f68e37 gh-151461: Fix encoding-related exception handling in file tokenizer (GH-151462) 2026-06-14 12:33:03 +00:00
Stan Ulbrych 4b44b1e1fd gh-151238: Check for _get_resized_exprs failure in _PyPegen_{joined,template}_str (#151259) 2026-06-11 15:26:46 +01:00
Grant Herman 262625fa30 gh-150207: Raise MemoryError on tokenizer allocation failure instead of crashing (#150275) 2026-06-06 01:58:35 +00: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
Bartosz Sławecki 448d7b96c1 gh-145239: Accept unary plus literal pattern (#148566)
Add '+' alternatives to signed_number and signed_real_number grammar
rules, mirroring how unary minus is already handled for pattern matching.
Unary plus is a no-op on numbers so the value is returned directly without
wrapping in a UnaryOp node.
2026-04-23 22:07:28 +03:00
Stan Ulbrych 1795fccfbc gh-148157: Check for _PyPegen_add_type_comment_to_arg fail in _PyPegen_name_default_pair (#148158) 2026-04-06 12:56:36 +01:00
Karolina SurmaandVictor 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
Stan Ulbrych e1c224624a gh-145783: Propagate errors raised in NEW_TYPE_COMMENT (#145784) 2026-03-13 11:05:20 +00:00
86a0756234 gh-140594: Fix an out of bounds read when feeding NUL byte to PyOS_StdioReadline() (#140910)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-12 10:46:36 +00:00
Sergey Miryanov d19de375a2 GH-145247: Use _PyTuple_FromPair in Parser and Python (#145842)
Use _PyTuple_FromPair in Parser and Python
2026-03-11 21:08:18 +00:00
Pieter Eendebak 4f87c99a5a gh-145376: Fix refleak & pointer type bug in uncommon code paths in Parser/ (GH-145684) 2026-03-11 14:24:15 +01:00
Pablo Galindo SalgadoandBartosz Sławecki 09e8c38231 gh-145241: specialize SyntaxError for single trailing-comma with item (#145282)
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2026-02-28 02:24:06 +00:00
Pablo Galindo Salgado 98b1e51927 gh-145234: Normalize decoded CR in string tokenizer (#145281) 2026-02-27 12:44:54 +00:00
AdamKorcz 3fc945df22 gh-144872: fix heap buffer overflow _PyTokenizer_ensure_utf8 (#144807) 2026-02-26 22:35:08 +00:00
Ramin Farajpour Cami e6110efd03 gh-144759: Fix undefined behavior from NULL pointer arithmetic in lexer (#144788)
Guard against NULL pointer arithmetic in `_PyLexer_remember_fstring_buffers`
and `_PyLexer_restore_fstring_buffers`. When `start` or `multi_line_start`
are NULL (uninitialized in tok_mode_stack[0]), performing `NULL - tok->buf`
is undefined behavior. Add explicit NULL checks to store -1 as sentinel
and restore NULL accordingly.

Add test_lexer_buffer_realloc_with_null_start to test_repl.py that
exercises the code path where the lexer buffer is reallocated while
tok_mode_stack[0] has NULL start/multi_line_start pointers. This
triggers _PyLexer_remember_fstring_buffers and verifies the NULL
checks prevent undefined behavior.
2026-02-15 14:39:57 +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 hartzandJelle 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
cui 0fa1fc69f3 gh-144322: typo This errors to These errors (#144323) 2026-01-29 13:26:38 +00:00
Jelle ZijlstraandVictor 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
Sam Gross 2b4feee648 gh-122581: Use parser mutex in default build for subinterpreters (gh-142959) 2025-12-20 15:37:31 -05:00
AZero13 d844d22cb0 gh-142724: fix error path in _PyPegen_raise_tokenizer_init_error (#142725) 2025-12-14 21:23:38 +00:00
Pablo Galindo Salgado c433986005 gh-142236: Improve error location for missing comma in string concatenations (#142330) 2025-12-11 14:47:26 +00:00