mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-09 22:25:53 +08:00
Add conversion issues.
This commit is contained in:
@@ -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):
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ FAILING_EXAMPLES = [
|
|||||||
'f"{\\}"',
|
'f"{\\}"',
|
||||||
'f"{\'\\\'}"',
|
'f"{\'\\\'}"',
|
||||||
'f"{#}"',
|
'f"{#}"',
|
||||||
|
"f'{1!b}'",
|
||||||
]
|
]
|
||||||
|
|
||||||
GLOBAL_NONLOCAL_ERROR = [
|
GLOBAL_NONLOCAL_ERROR = [
|
||||||
|
|||||||
Reference in New Issue
Block a user