diff --git a/parso/python/errors.py b/parso/python/errors.py index c50fa4f..cfb8380 100644 --- a/parso/python/errors.py +++ b/parso/python/errors.py @@ -846,26 +846,12 @@ class _TryStmtRule(SyntaxRule): @ErrorFinder.register_rule(type='fstring') class _FStringRule(SyntaxRule): _fstring_grammar = None - message_single_closing = "f-string: single '}' is not allowed" # f'}' message_nested = "f-string: expressions nested too deeply" message_conversion = "f-string: invalid conversion character: expected 's', 'r', or 'a'" def _check_format_spec(self, format_spec, depth): self._check_fstring_contents(format_spec.children[1:], depth) - def _check_string_part(self, fstring_string): - index = -1 - value = fstring_string.value - while True: - index = value.find('}', index + 1) - if index == -1: - break # No further } found, we're finished. - elif index + 1 != len(value) and value[index + 1]: - # It's }}, which is totally ok. - index += 1 - else: - self.add_issue(fstring_string, message=self.message_single_closing) - def _check_fstring_expr(self, fstring_expr, depth): if depth >= 2: self.add_issue(fstring_expr, message=self.message_nested) @@ -885,10 +871,7 @@ class _FStringRule(SyntaxRule): def _check_fstring_contents(self, children, depth=0): for fstring_content in children: - if fstring_content.type == 'fstring_string': - self._check_string_part(fstring_content) - else: - assert fstring_content.type == 'fstring_expr' + if fstring_content.type == 'fstring_expr': self._check_fstring_expr(fstring_content, depth) diff --git a/parso/python/fstring.py b/parso/python/fstring.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_python_errors.py b/test/test_python_errors.py index ca7be7f..67f3e1d 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -122,12 +122,14 @@ def _get_actual_exception(code): "SyntaxError: EOL while scanning string literal", "SyntaxError: unexpected character after line continuation character", ], line_nr + elif wanted == "SyntaxError: f-string: expecting '}'": + wanted = 'SyntaxError: EOL while scanning string literal' elif wanted == 'SyntaxError: f-string: empty expression not allowed': wanted = 'SyntaxError: invalid syntax' elif wanted == "SyntaxError: f-string expression part cannot include '#'": wanted = 'SyntaxError: invalid syntax' - elif wanted == "SyntaxError: f-string: expecting '}'": - wanted = 'SyntaxError: EOL while scanning string literal' + elif wanted == "SyntaxError: f-string: single '}' is not allowed": + wanted = 'SyntaxError: invalid syntax' return [wanted], line_nr