Revision on fstring issues (#100)

* f-string expression part cannot include a backslash
 * failing example `f"{'\n'}"` for tests
This commit is contained in:
Jarry Shaw
2020-01-10 04:49:34 +08:00
committed by Dave Halter
parent 55531ab65b
commit 84874aace3
2 changed files with 8 additions and 0 deletions

View File

@@ -863,6 +863,7 @@ class _TryStmtRule(SyntaxRule):
@ErrorFinder.register_rule(type='fstring')
class _FStringRule(SyntaxRule):
_fstring_grammar = None
message_expr = "f-string expression part cannot include a backslash"
message_nested = "f-string: expressions nested too deeply"
message_conversion = "f-string: invalid conversion character: expected 's', 'r', or 'a'"
@@ -873,6 +874,10 @@ class _FStringRule(SyntaxRule):
if depth >= 2:
self.add_issue(fstring_expr, message=self.message_nested)
expr = fstring_expr.children[1]
if '\\' in expr.get_code():
self.add_issue(expr, message=self.message_expr)
conversion = fstring_expr.children[2]
if conversion.type == 'fstring_conversion':
name = conversion.children[1]

View File

@@ -281,6 +281,9 @@ if sys.version_info >= (3, 6):
# Same as above, but for f-strings.
'f"s" b""',
'b"s" f""',
# f-string expression part cannot include a backslash
r'''f"{'\n'}"''',
]
FAILING_EXAMPLES.append('[a, 1] += 3')