[BE] Apply almost all remaining flake8-comprehension checks (#94676)

Applies the remaining flake8-comprehension fixes and checks. This changes replace all remaining unnecessary generator expressions with list/dict/set comprehensions which are more succinct, performant, and better supported by our torch.jit compiler. It also removes useless generators such as 'set(a for a in b)`, resolving it into just the set call.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/94676
Approved by: https://github.com/ezyang
This commit is contained in:
Aaron Gokaslan
2023-02-12 01:01:21 +00:00
committed by PyTorch MergeBot
parent 54c0f37646
commit 67d9790985
113 changed files with 500 additions and 526 deletions

View File

@ -54,7 +54,7 @@ def register_rendezvous_handler(scheme, handler):
# Query will have format "rank=0&world_size=1" and is
# converted into {"rank": 0, "world_size": 1}
def _query_to_dict(query: str) -> Dict[str, str]:
return dict((pair[0], pair[1]) for pair in (pair.split("=") for pair in filter(None, query.split("&"))))
return {pair[0]: pair[1] for pair in (pair.split("=") for pair in filter(None, query.split("&")))}
def _rendezvous_helper(url: str, rank: int, world_size_opt: Optional[int], **kwargs):