mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[BE]: Apply PERF401 autofixes from ruff (#140980)
* Automatically applies ruff rule 401. Turns loops into equivalent list comprehensions which are faster and do not leak the scope of the loop variables. * list comprehensions not only often have better typing, but are 50+% faster than for loops on overhead. They also preserve length information etc and are better for the interpreter to optimize. * Manually went back and made mypy happy after the change. * Also fixed style lints in files covered by flake8 but not by pyfmt Pull Request resolved: https://github.com/pytorch/pytorch/pull/140980 Approved by: https://github.com/justinchuby, https://github.com/malfet
This commit is contained in:
committed by
PyTorch MergeBot
parent
8d708090c0
commit
12e95aa4ee
@ -952,9 +952,10 @@ class PatternPrettyPrinter:
|
||||
assert hasattr(obj, "pretty_print")
|
||||
out_str = obj.pretty_print(pp=pp)
|
||||
|
||||
output = []
|
||||
for key in pp.memoized_objs_names:
|
||||
output.append(f"{pp.memoized_objs_names[key]} = {pp.memoized_objs_pp[key]}")
|
||||
output = [
|
||||
f"{pp.memoized_objs_names[key]} = {pp.memoized_objs_pp[key]}"
|
||||
for key in pp.memoized_objs_names
|
||||
]
|
||||
|
||||
output.append(f"{output_name} = {out_str}")
|
||||
|
||||
@ -1361,9 +1362,7 @@ def register_replacement(
|
||||
return False
|
||||
|
||||
def normalize_args(**kwargs: Any) -> List[Any]:
|
||||
args = []
|
||||
for name in argnames_static:
|
||||
args.append(kwargs.pop(name))
|
||||
args = [kwargs.pop(name) for name in argnames_static]
|
||||
for i in range(1, len(kwargs) + 1):
|
||||
if f"tangents_{i}" not in kwargs:
|
||||
break
|
||||
|
Reference in New Issue
Block a user