8000 Revert "Fix handling of invalid conversion characters" · python/cpython@270b661 · GitHub
[go: up one dir, main page]

Skip to content

Commit 270b661

Browse files
committed
Revert "Fix handling of invalid conversion characters"
This reverts commit b80d9ea.
1 parent e1940e5 commit 270b661

File tree

3 files changed

+512
-749
lines changed

3 files changed

+512
-749
lines changed

Grammar/python.gram

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ yield_stmt[stmt_ty]: y=yield_expr { _PyAST_Expr(y, EXTRA) }
194194

195195
assert_stmt[stmt_ty]: 'assert' a=expression b=[',' z=expression { z }] { _PyAST_Assert(a, b, EXTRA) }
196196

197-
import_stmt[stmt_ty]:
197+
import_stmt[stmt_ty]:
198198
| invalid_import
199199
| import_name
200200
| import_from
@@ -415,8 +415,8 @@ try_stmt[stmt_ty]:
415415
| invalid_try_stmt
416416
| 'try' &&':' b=block f=finally_block { _PyAST_Try(b, NULL, NULL, f, EXTRA) }
417417
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _PyAST_Try(b, ex, el, f, EXTRA) }
418-
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_star_block+ el=[else_block] f=[finally_block] {
419-
CHECK_VERSION(stmt_ty, 11, "Exception groups are",
418+
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_star_block+ el=[else_block] f=[finally_block] {
419+
CHECK_VERSION(stmt_ty, 11, "Exception groups are",
420420
_PyAST_TryStar(b, ex, el, f, EXTRA)) }
421421

422422

@@ -1263,7 +1263,7 @@ invalid_group:
12631263
invalid_import:
12641264
| a='import' dotted_name 'from' dotted_name {
12651265
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "Did you mean to use 'from ... import ...' instead?") }
1266-
1266+
12671267
invalid_import_from_targets:
12681268
| import_from_as_names ',' NEWLINE {
12691269
RAISE_SYNTAX_ERROR("trailing comma not allowed without surrounding parentheses") }
@@ -1362,7 +1362,3 @@ invalid_replacement_field:
13621362
| '{' a=':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: expression required before ':'") }
13631363
| '{' a='!' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: expression required before '!'") }
13641364
| '{' a='}' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: empty expression not allowed") }
1365-
| '{' (yield_expr | star_expressions) "="? invalid_conversion_character
1366-
invalid_conversion_character:
1367-
| a="!" &(':'|'}') { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: missed conversion character") }
1368-
| a="!" !NAME { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: invalid conversion character") }

Lib/test/test_fstring.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,16 +1120,11 @@ def test_conversions(self):
11201120
"f'{3!:}'",
11211121
])
11221122

1123-
for conv_identifier in 'g', 'A', 'G', 'ä', 'ɐ', 'ª':
1123+
for conv in 'g', 'A', '3', 'G', '!', 'ä', 'ɐ', 'ª':
11241124
self.assertAllRaise(SyntaxError,
11251125
"f-string: invalid conversion character %r: "
1126-
"expected 's', 'r', or 'a'" % conv_identifier,
1127-
["f'{3!" + conv_identifier + "}'"])
1128-
1129-
for conv_non_identifier in '3', '!':
1130-
self.assertAllRaise(SyntaxError,
1131-
"f-string: invalid conversion character",
1132-
["f'{3!" + conv_non_identifier + "}'"])
1126+
"expected 's', 'r', or 'a'" % conv,
1127+
["f'{3!" + conv + "}'"])
11331128

11341129
for conv in ' s', ' s ':
11351130
self.assertAllRaise(SyntaxError,

0 commit comments

Comments
 (0)
0