172 Commits
Author SHA1 Message Date
sobolevn 7b12a415c8 gh-152631: Fix ast.parse on lazy imports with older feature_version (#152632) 2026-10-25 20:35:59 +00:00
Pablo Galindo SalgadoandLysandros Nikolaou b77cb891e9 gh-153568: Skip the expression precedence chain for single-token atoms (#153575)
A bare name or number followed by a token that cannot extend an expression now produces its AST node directly. This avoids the expression precedence chain for common arguments, assignments, and subscripts.

Rules declare the hook with a fastpath flag. The Rule constructor exposes memo and fastpath attributes, and the C generator emits the hook call.

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2026-10-23 14:23:10 -07:00
Lysandros Nikolaou e548b472f3 gh-153195: Allow splitting the PEG grammar into several files (#159917)
Add an @include meta to pegen: the rules of an included grammar file are
appended to the including file's rules. The C generator emits the rules
of each included file into a separate C file next to the main output.

Use it to move the invalid_* rules from Grammar/python.gram into
Grammar/invalid.gram, which generates Parser/parser_invalid.c.
2026-10-23 12:58:39 -07:00
Sergey B Kirpichev 198bc76836 gh-151464: exclude '<>' token from tokenize output (#154854)
* gh-151464: exclude '<>' token from tokenize output

Was:
```
$ echo '1 <> 2' | python -m tokenize
1,0-1,1:            NUMBER         '1'
1,2-1,4:            OP             '<>'
1,5-1,6:            NUMBER         '2'
1,6-1,7:            NEWLINE        '\n'
2,0-2,0:            ENDMARKER      ''
```

Now (regardless on ``__future__.barry_as_FLUFL`` import):
```
$ echo '1 <> 2' | ./python -m tokenize
1,0-1,1:            NUMBER         '1'
1,2-1,3:            OP             '<'
1,3-1,4:            OP             '>'
1,5-1,6:            NUMBER         '2'
1,6-1,7:            NEWLINE        '\n'
2,0-2,0:            ENDMARKER      ''
```
in accordance with the Grammar:
https://docs.python.org/3.14/reference/lexical_analysis.html#operators-and-delimiters

Also adds a custom error message for ``<>`` ("not equal" in Pascal
and Python 2).

* +1

* address review: lowercase and move invalid rule

* address review: news

* address review: move test_guido_as_bdfl_ineq_tokens()

* address review: revert _PyTokenizer_From* changes

* + revert unrelated change

* address review: remove whatsnew entry
2026-09-25 19:51:59 +01:00
7884f48af4 gh-152708: Fix AST generation asymmetry for unary positive in match statements (#152712)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: johnslavik <bartosz@ilikepython.com>
2026-09-23 19:56:53 -07:00
Pablo Galindo Salgado d8a1072491 gh-153568: Reduce parser allocations (#157374) 2026-09-16 16:10:40 -04:00
Pablo Galindo Salgado c3f23734a8 gh-153568: Share expression parsing with assignment targets (#157450)
* gh-153568: Share expression parsing with assignment targets

* Clarify target parsing contracts and AST expectations
2026-09-14 16:53:25 +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
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
Aniket 0f501b9b74 gh-146495: Improve SyntaxError message for && and || operators (#150906) 2026-06-27 18:57:10 +02: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
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
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
Pablo Galindo Salgado c433986005 gh-142236: Improve error location for missing comma in string concatenations (#142330) 2025-12-11 14:47:26 +00:00
Brian Schubert 3dab11f888 gh-138944: Fix SyntaxError message for invalid syntax following valid import-as statement (#138945) 2025-10-26 22:35:21 +00:00
sobolevnandBartosz Sławecki 92c0c45563 gh-138857: Improve error message for case outside of match (#138858)
* gh-138857: Improve error message for `case` outside of `match`

---------

Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
2025-10-24 11:20:54 +02:00
Bartosz Sławecki b3b0d75069 gh-140253: Improve the syntax error from an ill-positioned double-star subpattern (#140254) 2025-10-22 21:29:14 +03:00
sobolevn cf8f36fe0a gh-138716: Fix assert a := b syntax error message (#138718) 2025-09-10 16:05:16 +03:00
sobolevn 6bc65c30ff gh-136616: Improve assert syntax error messages (#136653) 2025-09-09 23:26:22 +03:00
Pablo Galindo Salgado 4e08a9f97a gh-137078: Fix keyword typo recognition when executed over files (#137079) 2025-08-15 15:14:13 +00:00
c5e77af131 gh-132661: Disallow Template/str concatenation after PEP 750 spec update (#135996)
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2025-07-21 08:44:26 +02:00
sobolevn 7e33558455 gh-135422: Fix regression in SyntaxError messages after #134036 (#135423) 2025-06-30 21:52:26 +03:00
sobolevn 0d9ccc87a2 gh-134036: Improve error messages for invalid raise statements (#134077) 2025-06-06 01:51:06 +01:00
sobolevn 84914ad0e5 gh-133999: Fix except parsing regression in 3.14 (#134035) 2025-05-17 17:57:02 +03:00
Rafael FontenelleandAdam Turner 6df39765e6 Remove trailing whitespace from python.gram (#133858)
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
2025-05-14 10:52:19 +03:00
Stan Ulbrych dbca27cfca gh-133379: Fix misuse of the term "arguments" in error messages (GH-133382)
The right term is "parameters".
2025-05-10 15:00:43 +03:00
sobolevn ca0a96dfaa gh-133194: Fix regression with PEP 758 parsing on older feature_version (#133289)
gh-133192: Fix regression with PEP 758 parsing on older `feature_version`
2025-05-03 10:33:14 +03:00
sobolevn a6ddd078d0 gh-123539: Improve SyntaxError msg for import as with not a name (#123629) 2025-05-02 08:34:13 +00:00
sobolevn 5cdd49b3f4 gh-133196: Guard PEP 750 grammar with CHECK_VERSION (#133225) 2025-05-01 09:17:07 +02:00
sobolevn b1f893875b gh-133194: Add CHECK_VERSION to new PEP758 grammar (#133195) 2025-04-30 13:39:26 +03: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
Rafael Fontenelle fd0f5d0a5e Remove trailing whitespace from python.gram (#133175) 2025-04-30 10:35:15 +02:00
Steele Farnsworth 99b71efe8e gh-129858: Special syntax error for elif block after else (#129902) 2025-04-25 01:25:48 +00:00
Pablo Galindo SalgadoandŁukasz Langa bf3a0a1c0f gh-132449: Improve syntax error messages for keywords with typos (#132450)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2025-04-22 11:01:55 +02:00
Pablo Galindo Salgado c2ac662f28 gh-131831: Implement PEP 758 – Allow except and except* expressions without parentheses (#131833) 2025-04-01 19:04:56 +00:00
bcc9a5dddb gh-129515: Clarify syntax error messages for conditional expressions (#129880)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-02-18 21:43:19 +00:00
Pablo Galindo Salgado 3bd3e09588 gh-125331: Allow the parser to activate future imports on the fly (#125482) 2025-02-14 04:54:56 +00:00
Pablo Galindo Salgado 6fb5138776 gh-88535: Improve syntax error for wrongly closed strings (#26633) 2025-02-13 01:30:20 +00:00
Rigel Di Scala 39c859f6ff gh-122951: Simplify the grammar of the assignment rule (#124998) 2024-10-06 11:55:56 +02:00
sobolevn 23f159ae71 gh-123562: Improve SyntaxError message for case ... as a.b (#123563) 2024-09-02 13:11:44 +02:00
sobolevn e451a8937d gh-123440: Improve error message for except as used with not a name (#123442) 2024-08-30 17:21:59 +01:00
Petr Viktorin 31a4fb3c74 gh-119724: Revert "bpo-45759: Better error messages for non-matching 'elif'/'else' statements (#29513)" (#119974)
This reverts commit 1c8f912ebd.
2024-06-03 18:10:15 -07:00
Petr Viktorin 48f21b3631 gh-118235: Move RAISE_SYNTAX_ERROR actions to invalid rules and make sure they stay there (GH-119731)
The Full Grammar specification in the docs omits rule actions, so grammar rules that raise a syntax error looked like valid syntax.
This was solved in ef940de by hiding those rules in the custom syntax highlighter.

This moves all syntax-error alternatives to invalid rules, adds a validator that ensures that actions containing RAISE_SYNTAX_ERROR are in invalid rules, and reverts the syntax highlighter hack.
2024-05-30 09:27:32 +02:00
Nikita Sobolev b60d4c0d53 gh-118090: Improve error message for empty type param brackets (GH-118091) 2024-05-07 14:01:06 +02: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
Nikita Sobolev 51aefc5bf9 gh-118323: Document && grammar syntax (#118324) 2024-04-27 11:36:06 +01:00
David Rubin 9b280ab0ab gh-116988: Remove duplicates of annotated_rhs in the Grammar (#117004) 2024-04-24 18:16:06 +01:00
Nikita Sobolev de1f686827 gh-118082: Improve import without names syntax error message (#118083) 2024-04-23 13:00:52 +01:00