mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 05:14:29 +08:00
Properly check for invalid conversion character with f-string debugging syntax (#156)
This commit is contained in:
@@ -957,7 +957,11 @@ class _FStringRule(SyntaxRule):
|
|||||||
if '\\' in expr.get_code():
|
if '\\' in expr.get_code():
|
||||||
self.add_issue(expr, message=self.message_expr)
|
self.add_issue(expr, message=self.message_expr)
|
||||||
|
|
||||||
conversion = fstring_expr.children[2]
|
children_2 = fstring_expr.children[2]
|
||||||
|
if children_2.type == 'operator' and children_2.value == '=':
|
||||||
|
conversion = fstring_expr.children[3]
|
||||||
|
else:
|
||||||
|
conversion = children_2
|
||||||
if conversion.type == 'fstring_conversion':
|
if conversion.type == 'fstring_conversion':
|
||||||
name = conversion.children[1]
|
name = conversion.children[1]
|
||||||
if name.value not in ('s', 'r', 'a'):
|
if name.value not in ('s', 'r', 'a'):
|
||||||
|
|||||||
@@ -357,3 +357,7 @@ if sys.version_info[:2] >= (3, 8):
|
|||||||
'(None := 1)',
|
'(None := 1)',
|
||||||
'(__debug__ := 1)',
|
'(__debug__ := 1)',
|
||||||
]
|
]
|
||||||
|
# f-string debugging syntax with invalid conversion character
|
||||||
|
FAILING_EXAMPLES += [
|
||||||
|
"f'{1=!b}'",
|
||||||
|
]
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ def test_valid(code, grammar):
|
|||||||
|
|
||||||
# invalid conversion characters
|
# invalid conversion characters
|
||||||
'f"{1!{a}}"',
|
'f"{1!{a}}"',
|
||||||
|
'f"{1=!{a}}"',
|
||||||
'f"{!{a}}"',
|
'f"{!{a}}"',
|
||||||
|
|
||||||
# The curly braces must contain an expression
|
# The curly braces must contain an expression
|
||||||
|
|||||||
Reference in New Issue
Block a user