Properly check for invalid conversion character with f-string debugging syntax (#156)

This commit is contained in:
Saiyang Gou
2020-11-18 01:56:04 -08:00
committed by GitHub
parent 634df56d90
commit 034a9e8944
3 changed files with 10 additions and 1 deletions

View File

@@ -957,7 +957,11 @@ class _FStringRule(SyntaxRule):
if '\\' in expr.get_code():
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':
name = conversion.children[1]
if name.value not in ('s', 'r', 'a'):

View File

@@ -357,3 +357,7 @@ if sys.version_info[:2] >= (3, 8):
'(None := 1)',
'(__debug__ := 1)',
]
# f-string debugging syntax with invalid conversion character
FAILING_EXAMPLES += [
"f'{1=!b}'",
]

View File

@@ -79,6 +79,7 @@ def test_valid(code, grammar):
# invalid conversion characters
'f"{1!{a}}"',
'f"{1=!{a}}"',
'f"{!{a}}"',
# The curly braces must contain an expression