Add conversion issues.

This commit is contained in:
Dave Halter
2017-08-26 03:13:59 +02:00
parent 8a448303d1
commit 7d4aa755a5
2 changed files with 9 additions and 3 deletions

View File

@@ -846,7 +846,7 @@ class _FStringRule(SyntaxRule):
message_comment = "f-string expression part cannot include '#'" # f'{#}' message_comment = "f-string expression part cannot include '#'" # f'{#}'
"f-string: unterminated string" # f'{"}' "f-string: unterminated string" # f'{"}'
"f-string: mismatched '(', '{', or '['" "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: unexpected end of string" # Doesn't really happen?!
"f-string: expecting '}'" # f'{' "f-string: expecting '}'" # f'{'
@@ -864,8 +864,13 @@ class _FStringRule(SyntaxRule):
parsed = self._load_grammar().parse_leaf(fstring) parsed = self._load_grammar().parse_leaf(fstring)
for child in parsed.children: for child in parsed.children:
type = child.type if child.type == 'expression':
if 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]) self._check_expression(child.children[1])
def _check_expression(self, python_expr): def _check_expression(self, python_expr):

View File

@@ -144,6 +144,7 @@ FAILING_EXAMPLES = [
'f"{\\}"', 'f"{\\}"',
'f"{\'\\\'}"', 'f"{\'\\\'}"',
'f"{#}"', 'f"{#}"',
"f'{1!b}'",
] ]
GLOBAL_NONLOCAL_ERROR = [ GLOBAL_NONLOCAL_ERROR = [