diff --git a/parso/python/errors.py b/parso/python/errors.py index fb84242..a6f3ae9 100644 --- a/parso/python/errors.py +++ b/parso/python/errors.py @@ -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] diff --git a/test/failing_examples.py b/test/failing_examples.py index 60cc8d6..8294ec0 100644 --- a/test/failing_examples.py +++ b/test/failing_examples.py @@ -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')