From 7d4aa755a571e77cfe0ddce01f599dcb95652691 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 26 Aug 2017 03:13:59 +0200 Subject: [PATCH] Add conversion issues. --- parso/python/errors.py | 11 ++++++++--- test/failing_examples.py | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/parso/python/errors.py b/parso/python/errors.py index 537844a..0efea5f 100644 --- a/parso/python/errors.py +++ b/parso/python/errors.py @@ -846,7 +846,7 @@ class _FStringRule(SyntaxRule): message_comment = "f-string expression part cannot include '#'" # f'{#}' "f-string: unterminated string" # f'{"}' "f-string: mismatched '(', '{', or '['" - "f-string: invalid conversion character: expected 's', 'r', or 'a'" # f'{1!b}' + message_conversion = "f-string: invalid conversion character: expected 's', 'r', or 'a'" "f-string: unexpected end of string" # Doesn't really happen?! "f-string: expecting '}'" # f'{' @@ -864,8 +864,13 @@ class _FStringRule(SyntaxRule): parsed = self._load_grammar().parse_leaf(fstring) for child in parsed.children: - type = child.type - if type == 'expression': + if child.type == 'expression': + for c in child.children: + if c.type == 'python_expr': + self._check_expression(c) + elif c.type == 'conversion': + if c.value not in ('s', 'r', 'a'): + self.add_issue(c, message=self.message_conversion) self._check_expression(child.children[1]) def _check_expression(self, python_expr): diff --git a/test/failing_examples.py b/test/failing_examples.py index 89dc359..d68856c 100644 --- a/test/failing_examples.py +++ b/test/failing_examples.py @@ -144,6 +144,7 @@ FAILING_EXAMPLES = [ 'f"{\\}"', 'f"{\'\\\'}"', 'f"{#}"', + "f'{1!b}'", ] GLOBAL_NONLOCAL_ERROR = [