[torchgen] Fix ruff format for # fmt: skip comment for function signature (#155909)

See also:

- astral-sh/ruff#18658

This fix follows the suggestion from:

- https://github.com/astral-sh/ruff/issues/18658#issuecomment-2970130276

Pull Request resolved: https://github.com/pytorch/pytorch/pull/155909
Approved by: https://github.com/ezyang
This commit is contained in:
Xuehai Pan
2025-06-14 15:05:28 +08:00
committed by PyTorch MergeBot
parent d859e65826
commit 736a15a81a

View File

@ -212,17 +212,17 @@ def format_function_signature(
if len(sig) <= 80 or len(arguments) == 0 or tuple(arguments) == ("self",): if len(sig) <= 80 or len(arguments) == 0 or tuple(arguments) == ("self",):
return sig return sig
arguments = [f" {arg}," for arg in arguments] lines = [
return "\n".join( f"def {name}(",
( *(f" {arg}," for arg in arguments),
f"def {name}(", f"){return_type}: ...",
*( ]
arg if len(arg) <= 80 else f" # fmt: off\n{arg}\n # fmt: on" sig = "\n".join(lines)
for arg in arguments if all(len(line) <= 80 for line in lines):
), return sig
f"){return_type}: ...", # ruff format bug for compound statements: https://github.com/astral-sh/ruff/issues/18658
) # use `skip` instead of `on` + `off`
).replace(" # fmt: off\n # fmt: on\n", "") return sig.removesuffix(" ...") + " # fmt: skip\n ..."
@dataclass(frozen=True) @dataclass(frozen=True)