Skip to content

Commit

Permalink
style: add comments for easier understanding
Browse files Browse the repository at this point in the history
  • Loading branch information
Hocnonsense committed Jan 29, 2024
1 parent c272109 commit 4f859c0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions snakemake/parser.py
Expand Up @@ -62,7 +62,7 @@ def is_string(token):
return token.type == tokenize.STRING


def is_fstring(token):
def is_fstring_start(token):
return sys.version_info >= (3, 12) and token.type == tokenize.FSTRING_START


Expand Down Expand Up @@ -108,6 +108,9 @@ def indentation(self, token):
self.was_indented |= self.indent > 0

def parse_fstring(self, token: tokenize.TokenInfo):
# only for python >= 3.12, since then python changed the
# parsing manner of f-string, see
# [pep-0701](https://peps.python.org/pep-0701)
isin_fstring = 1
t = token.string
for t1 in self.snakefile:
Expand All @@ -132,7 +135,8 @@ def consume(self):
self.indentation(token)
try:
for t, orig in self.state(token):
if is_fstring(token):
# python >= 3.12 only
if is_fstring_start(token):
t = self.parse_fstring(token)
if self.lasttoken == "\n" and not t.isspace():
yield INDENT * self.effective_indent, orig
Expand Down

0 comments on commit 4f859c0

Please sign in to comment.