mirror of
https://github.com/davidhalter/parso.git
synced 2026-05-18 14:30:04 +08:00
Fix the fstring syntax if there's a conversion with exclamation mark
This commit is contained in:
+12
-2
@@ -864,7 +864,7 @@ class _FStringRule(SyntaxRule):
|
|||||||
cls._fstring_grammar = parso.load_grammar(language='python-f-string')
|
cls._fstring_grammar = parso.load_grammar(language='python-f-string')
|
||||||
return cls._fstring_grammar
|
return cls._fstring_grammar
|
||||||
|
|
||||||
def _check_type(self, fstring_string):
|
def _check_string_part(self, fstring_string):
|
||||||
index = -1
|
index = -1
|
||||||
value = fstring_string.value
|
value = fstring_string.value
|
||||||
while True:
|
while True:
|
||||||
@@ -877,10 +877,20 @@ class _FStringRule(SyntaxRule):
|
|||||||
else:
|
else:
|
||||||
self.add_issue(fstring_string, message=self.message_single_closing)
|
self.add_issue(fstring_string, message=self.message_single_closing)
|
||||||
|
|
||||||
|
def _check_fstring_expr(self, fstring_expr):
|
||||||
|
conversion = fstring_expr.children[2]
|
||||||
|
if conversion.type == 'fstring_conversion':
|
||||||
|
name = conversion.children[1]
|
||||||
|
if name.value not in ('s', 'r', 'a'):
|
||||||
|
self.add_issue(name, message=self.message_conversion)
|
||||||
|
|
||||||
def is_issue(self, fstring):
|
def is_issue(self, fstring):
|
||||||
for fstring_content in fstring.children[1:-1]:
|
for fstring_content in fstring.children[1:-1]:
|
||||||
if fstring_content.type == 'fstring_string':
|
if fstring_content.type == 'fstring_string':
|
||||||
self._check_type(fstring_content)
|
self._check_string_part(fstring_content)
|
||||||
|
else:
|
||||||
|
assert fstring_content.type == 'fstring_expr'
|
||||||
|
self._check_fstring_expr(fstring_content)
|
||||||
return
|
return
|
||||||
print(fstring)
|
print(fstring)
|
||||||
if 'f' not in fstring.string_prefix.lower():
|
if 'f' not in fstring.string_prefix.lower():
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ def _create_token_collection(version_info):
|
|||||||
# recognized as two instances of =).
|
# recognized as two instances of =).
|
||||||
Operator = group(r"\*\*=?", r">>=?", r"<<=?",
|
Operator = group(r"\*\*=?", r">>=?", r"<<=?",
|
||||||
r"//=?", r"->",
|
r"//=?", r"->",
|
||||||
r"[+\-*/%&@`|^=<>]=?",
|
r"[+\-*/%&@`|^!=<>]=?",
|
||||||
r"~")
|
r"~")
|
||||||
|
|
||||||
Bracket = '[][(){}]'
|
Bracket = '[][(){}]'
|
||||||
|
|||||||
Reference in New Issue
Block a user