[BE] f-stringify torch/ and scripts (#105538)

This PR is a follow up on the pyupgrade series to convert more strings to use f-strings using `flynt`.

- https://docs.python.org/3/reference/lexical_analysis.html#f-strings
- https://pypi.org/project/flynt/

Command used:

```
flynt torch/ -ll 120
flynt scripts/ -ll 120
flynt tools/ -ll 120
```

and excluded `collect_env.py`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/105538
Approved by: https://github.com/ezyang, https://github.com/malfet
This commit is contained in:
Justin Chu
2023-07-21 08:23:48 -07:00
committed by PyTorch MergeBot
parent 4c73016ff2
commit 4cc1745b13
139 changed files with 350 additions and 670 deletions

View File

@ -37,8 +37,7 @@ def broadcast(a: List[int], b: List[int]):
if sizeA != sizeB and sizeA != 1 and sizeB != 1:
# TODO: only assertion error is bound in C++ compilation right now
raise AssertionError(
"The size of tensor a {} must match the size of tensor b ("
"{}) at non-singleton dimension {}".format(sizeA, sizeB, i)
f"The size of tensor a {sizeA} must match the size of tensor b ({sizeB}) at non-singleton dimension {i}"
)
expandedSizes.append(sizeB if sizeA == 1 else sizeA)
@ -81,8 +80,7 @@ def broadcast_inplace(a: List[int], b: List[int]):
dimsB = len(b)
if dimsB > dimsA:
raise AssertionError(
"The dims of tensor b ({}) must be less than or equal to"
"the dims of tensor a ({}) ".format(dimsB, dimsA)
f"The dims of tensor b ({dimsB}) must be less than or equal tothe dims of tensor a ({dimsA}) "
)
for dimA in range(dimsA):
dimB = dimsB - dimsA + dimA