mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
[BE] Enable ruff's UP rules and autoformat torchgen/ (#105423)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/105423 Approved by: https://github.com/Skylion007
This commit is contained in:
committed by
PyTorch MergeBot
parent
6ca3d7e1a2
commit
964d29f312
@ -105,7 +105,7 @@ def context(msg_fn: Callable[[], str]) -> Iterator[None]:
|
||||
# for getting mypy to do exhaustiveness checking
|
||||
# TODO: put this somewhere else, maybe
|
||||
def assert_never(x: NoReturn) -> NoReturn:
|
||||
raise AssertionError("Unhandled type: {}".format(type(x).__name__))
|
||||
raise AssertionError(f"Unhandled type: {type(x).__name__}")
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=None)
|
||||
@ -137,9 +137,9 @@ class FileManager:
|
||||
def _write_if_changed(self, filename: str, contents: str) -> None:
|
||||
old_contents: Optional[str]
|
||||
try:
|
||||
with open(filename, "r") as f:
|
||||
with open(filename) as f:
|
||||
old_contents = f.read()
|
||||
except IOError:
|
||||
except OSError:
|
||||
old_contents = None
|
||||
if contents != old_contents:
|
||||
# Create output directory if it doesn't exist
|
||||
@ -157,7 +157,7 @@ class FileManager:
|
||||
# TODO: Update the comment reference to the correct location
|
||||
if "generated_comment" not in env:
|
||||
comment = "@" + "generated by torchgen/gen.py"
|
||||
comment += " from {}".format(os.path.basename(template_path))
|
||||
comment += f" from {os.path.basename(template_path)}"
|
||||
env["generated_comment"] = comment
|
||||
template = _read_template(template_path)
|
||||
return template.substitute(env)
|
||||
@ -172,7 +172,7 @@ class FileManager:
|
||||
template_fn: str,
|
||||
env_callable: Callable[[], Union[str, Dict[str, Any]]],
|
||||
) -> None:
|
||||
filename = "{}/{}".format(self.install_dir, filename)
|
||||
filename = f"{self.install_dir}/{filename}"
|
||||
assert filename not in self.filenames, "duplicate file write {filename}"
|
||||
self.filenames.add(filename)
|
||||
if not self.dry_run:
|
||||
|
Reference in New Issue
Block a user