mirror of
https://github.com/davidhalter/parso.git
synced 2026-01-08 20:43:41 +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')
|
||||
class _FStringRule(SyntaxRule):
|
||||
_fstring_grammar = None
|
||||
message_expr = "f-string expression part cannot include a backslash"
|
||||
message_nested = "f-string: expressions nested too deeply"
|
||||
message_conversion = "f-string: invalid conversion character: expected 's', 'r', or 'a'"
|
||||
|
||||
@@ -873,6 +874,10 @@ class _FStringRule(SyntaxRule):
|
||||
if depth >= 2:
|
||||
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]
|
||||
if conversion.type == 'fstring_conversion':
|
||||
name = conversion.children[1]
|
||||
|
||||
Reference in New Issue
Block a user