Skip to content

gh-132661: Disallow Template/str concatenation after PEP 750 spec update #135996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5d5e187
Disallow explicit concat between Template and str
davepeck Jun 26, 2025
1cc778f
First pass at removing implicit Template/str concat
davepeck Jun 26, 2025
7ea498c
Merge branch 'main' into pep750-concat-update
davepeck Jun 30, 2025
d08c8b8
Merge branch 'main' into pep750-concat-update
davepeck Jul 8, 2025
c662041
Remove extraneous newline
davepeck Jul 8, 2025
b17b7c9
Add expected exception messages to tests
davepeck Jul 8, 2025
a0c1bb6
Remove _ast_unparse t/f implicit concat helper code
davepeck Jul 8, 2025
23988e8
Merge branch 'main' into pep750-concat-update
davepeck Jul 8, 2025
d7eadec
Add a parallel comment
davepeck Jul 8, 2025
cb1ad63
Add news blurb for PR.
davepeck Jul 8, 2025
741eaf2
One day, I may develop RST muscle memory.
davepeck Jul 8, 2025
8aeb512
Merge branch 'main' into pep750-concat-update
davepeck Jul 9, 2025
bf5447b
Merge branch 'main' into pep750-concat-update
davepeck Jul 9, 2025
7e7ea5a
Merge branch 'main' into pep750-concat-update
davepeck Jul 9, 2025
2f79337
Two minor tweaks
davepeck Jul 9, 2025
dacafdb
Use subtests; test both directions.
davepeck Jul 9, 2025
b272287
Update Objects/templateobject.c
davepeck Jul 9, 2025
ffae8e9
Update Misc/NEWS.d/next/Core_and_Builtins/2025-07-08-23-22-08.gh-issu…
davepeck Jul 9, 2025
c6ca45a
Fix bug in suggested change
davepeck Jul 9, 2025
091a2a9
Merge branch 'main' into pep750-concat-update
davepeck Jul 9, 2025
860caea
First pass at update to grammar and action_helpers.c
davepeck Jul 10, 2025
6a6f734
Merge branch 'main' into pep750-concat-update
davepeck Jul 10, 2025
860f81d
Simplify grammar
davepeck Jul 10, 2025
e0fe608
Use KNOWN_RANGE for string/t-string mix error messages
davepeck Jul 10, 2025
c9ed06b
Merge branch 'pep750-concat-update' of github.com:t-strings/cpython i…
davepeck Jul 10, 2025
3ebdd97
Merge branch 'main' into pep750-concat-update
davepeck Jul 10, 2025
ef1cd5c
Clean up ast_unparse.c append_tstring()
davepeck Jul 10, 2025
055af82
Merge branch 'main' into pep750-concat-update
davepeck Jul 15, 2025
ab393f7
Update Misc/NEWS.d/next/Core_and_Builtins/2025-07-08-23-22-08.gh-issu…
davepeck Jul 15, 2025
16e6a1f
Update Objects/templateobject.c
davepeck Jul 15, 2025
b81a807
Update error messages; add an assert(0)
davepeck Jul 15, 2025
b9bac0e
Simplify ast_unparase.c further
davepeck Jul 15, 2025
6b6acda
Fix news dangling reference (for now).
davepeck Jul 15, 2025
e5b03e8
Merge branch 'pep750-concat-update' of github.com:t-strings/cpython i…
davepeck Jul 15, 2025
6ea3af3
Fix exception assert message checks
davepeck Jul 16, 2025
5037f89
Remove no-longer used path in codegen.c
davepeck Jul 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update error messages; add an assert(0)
  • Loading branch information
davepeck committed Jul 15, 2025
commit b81a807c9d8bf3b16c8d0aec96df6204fbde023c
4 changes: 2 additions & 2 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1558,9 +1558,9 @@ invalid_tstring_conversion_character:

invalid_string_tstring_concat:
| a=(fstring|string)+ b[expr_ty]=tstring {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(PyPegen_last_item(a, expr_ty), b, "cannot mix t-strings with strings or f-strings") }
RAISE_SYNTAX_ERROR_KNOWN_RANGE(PyPegen_last_item(a, expr_ty), b, "cannot mix t-string literals with string or bytes literals") }
| a=tstring+ b[expr_ty]=(fstring|string) {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(PyPegen_last_item(a, expr_ty), b, "cannot mix t-strings with strings or f-strings") }
RAISE_SYNTAX_ERROR_KNOWN_RANGE(PyPegen_last_item(a, expr_ty), b, "cannot mix t-string literals with string or bytes literals") }

invalid_arithmetic:
| sum ('+'|'-'|'*'|'/'|'%'|'//'|'@') a='not' b=inversion { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "'not' after an operator must be parenthesized") }
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_tstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_literal_concatenation(self):

# Test disallowed mix of t-string and string/f-string (incl. bytes)
what = 't'
expected_msg = 'cannot mix t-strings with strings or f-strings'
expected_msg = 'cannot mix t-string literals with string or bytes literals'
for case in (
"t'{what}-string literal' 'str literal'",
"t'{what}-string literal' u'unicode literal'",
Expand Down
4 changes: 4 additions & 0 deletions Parser/action_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,10 @@ _PyPegen_concatenate_strings(Parser *p, asdl_expr_seq *strings,
case JoinedStr_kind:
f_string_found = 1;
break;
case TemplateStr_kind:
// python.gram handles this; we should never get here
assert(0);
break;
default:
f_string_found = 1;
break;
Expand Down
4 changes: 2 additions & 2 deletions Parser/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy