Simplify by using yield from (#97831)

The issues were found by SIM104 flake8-simplify in a local run.

I'll take a look on adding the check to the CI separately.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/97831
Approved by: https://github.com/Skylion007
This commit is contained in:
Sergii Dymchenko
2023-03-29 19:15:24 +00:00
committed by PyTorch MergeBot
parent 22b723132b
commit 477f3f555f
10 changed files with 13 additions and 25 deletions

View File

@ -110,8 +110,7 @@ def mapMaybe(func: Callable[[T], Optional[S]], xs: Iterable[T]) -> Iterator[S]:
# Map over function that returns sequences and cat them all together
def concatMap(func: Callable[[T], Sequence[S]], xs: Iterable[T]) -> Iterator[S]:
for x in xs:
for r in func(x):
yield r
yield from func(x)
# Conveniently add error context to exceptions raised. Lets us