mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-10 14:41:58 +08:00
Revision on fstring issues (#100)
* f-string expression part cannot include a backslash
* failing example `f"{'\n'}"` for tests
This commit is contained in:
@@ -863,6 +863,7 @@ class _TryStmtRule(SyntaxRule):
|
|||||||
@ErrorFinder.register_rule(type='fstring')
|
@ErrorFinder.register_rule(type='fstring')
|
||||||
class _FStringRule(SyntaxRule):
|
class _FStringRule(SyntaxRule):
|
||||||
_fstring_grammar = None
|
_fstring_grammar = None
|
||||||
|
message_expr = "f-string expression part cannot include a backslash"
|
||||||
message_nested = "f-string: expressions nested too deeply"
|
message_nested = "f-string: expressions nested too deeply"
|
||||||
message_conversion = "f-string: invalid conversion character: expected 's', 'r', or 'a'"
|
message_conversion = "f-string: invalid conversion character: expected 's', 'r', or 'a'"
|
||||||
|
|
||||||
@@ -873,6 +874,10 @@ class _FStringRule(SyntaxRule):
|
|||||||
if depth >= 2:
|
if depth >= 2:
|
||||||
self.add_issue(fstring_expr, message=self.message_nested)
|
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]
|
conversion = fstring_expr.children[2]
|
||||||
if conversion.type == 'fstring_conversion':
|
if conversion.type == 'fstring_conversion':
|
||||||
name = conversion.children[1]
|
name = conversion.children[1]
|
||||||
|
|||||||
@@ -281,6 +281,9 @@ if sys.version_info >= (3, 6):
|
|||||||
# Same as above, but for f-strings.
|
# Same as above, but for f-strings.
|
||||||
'f"s" b""',
|
'f"s" b""',
|
||||||
'b"s" f""',
|
'b"s" f""',
|
||||||
|
|
||||||
|
# f-string expression part cannot include a backslash
|
||||||
|
r'''f"{'\n'}"''',
|
||||||
]
|
]
|
||||||
FAILING_EXAMPLES.append('[a, 1] += 3')
|
FAILING_EXAMPLES.append('[a, 1] += 3')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user