From 87c06c0f5745f577c12db39852c6f763a2d41954 Mon Sep 17 00:00:00 2001 From: Hocnonsense <48747984+Hocnonsense@users.noreply.github.com> Date: Mon, 8 Jan 2024 16:18:07 +0800 Subject: [PATCH] fix: single line f-string format error in py3.12 (#2588) ### Description fix #2586 for some cases do not considered in #2485 ### QC * [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). --- snakemake/parser.py | 11 +++++------ tests/test_fstring/Snakefile | 4 ++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/snakemake/parser.py b/snakemake/parser.py index 4f7f4582e..ba3433db7 100644 --- a/snakemake/parser.py +++ b/snakemake/parser.py @@ -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 @@ -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 ")" @@ -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 diff --git a/tests/test_fstring/Snakefile b/tests/test_fstring/Snakefile index d050ed8cc..8dc20ed6f 100644 --- a/tests/test_fstring/Snakefile +++ b/tests/test_fstring/Snakefile @@ -10,6 +10,10 @@ rule unit1: "echo '>'{output}'<'; touch {output}; sleep 1" +rule unit2: + shell: + f"ls" + assert ( f""" {