Skip to content

Commit

Permalink
fix: single line f-string format error in py3.12 (#2588)
Browse files Browse the repository at this point in the history
### Description

fix #2586 for some cases do not considered in #2485

### QC
<!-- Make sure that you can tick the boxes below. -->

* [x] The PR contains a test case for the changes or the changes are
already covered by an existing test case.
* [ ] The documentation (`docs/`) is updated to reflect the changes or
this is not necessary (e.g. if the change does neither modify the
language nor the behavior or functionalities of Snakemake).
  • Loading branch information
Hocnonsense committed Jan 8, 2024
1 parent ba22e07 commit 87c06c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 5 additions & 6 deletions snakemake/parser.py
Expand Up @@ -536,7 +536,7 @@ def __init__(self, snakefile, rulename, base_indent=0, dedent=0, root=True):
super().__init__(
snakefile, rulename, base_indent=base_indent, dedent=dedent, root=root
)
self.cmd = list()
self.cmd: list[tuple[str, tokenize.TokenInfo]] = []
self.token = None
if self.overwrite_cmd is not None:
self.block_content = self.overwrite_block_content
Expand Down Expand Up @@ -564,7 +564,7 @@ def end(self):
yield INDENT * (self.effective_indent + 1)
yield self.end_func
yield "("
yield "\n".join(self.cmd)
yield from self.cmd
yield from self.args()
yield "\n"
yield ")"
Expand All @@ -577,19 +577,18 @@ def decorate_end(self, token):
self.error(
"Command must be given as string after the shell keyword.", token
)
for t in self.end():
yield t, self.token
yield from super().decorate_end(self.token)

def block_content(self, token):
self.token = token
self.cmd.append(token.string)
self.cmd.append((token.string, token))
yield token.string, token

def overwrite_block_content(self, token):
if self.token is None:
self.token = token
cmd = repr(self.overwrite_cmd)
self.cmd.append(cmd)
self.cmd.append((cmd, token))
yield cmd, token


Expand Down
4 changes: 4 additions & 0 deletions tests/test_fstring/Snakefile
Expand Up @@ -10,6 +10,10 @@ rule unit1:
"echo '>'{output}'<'; touch {output}; sleep 1"


rule unit2:
shell:
f"ls"

assert (
f"""
{
Expand Down

0 comments on commit 87c06c0

Please sign in to comment.