From 85f38b8a331a65cb1b1035104f989417b5c27078 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Sat, 15 Apr 2023 15:33:42 +0000 Subject: [PATCH] [BE] Update flake8-comprehensions and adapt to rule C418 (#99178) Applies rule C418 and fixes all instances of it. Also updates flake8-comprehension Pull Request resolved: https://github.com/pytorch/pytorch/pull/99178 Approved by: https://github.com/ezyang --- .flake8 | 2 +- .lintrunner.toml | 2 +- test/jit/test_list_dict.py | 6 +++--- test/test_datapipe.py | 2 +- torch/ao/pruning/_mappings.py | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.flake8 b/.flake8 index c18caef53039ba..4d1aa57ef7421f 100644 --- a/.flake8 +++ b/.flake8 @@ -14,7 +14,7 @@ ignore = # these ignores are from flake8-bugbear; please fix! B007,B008,B017,B019,B020,B023,B024,B026,B027,B028,B903,B904,B905,B906,B907 # these ignores are from flake8-comprehensions; please fix! - C407 + C407,C419, # these ignores are from flake8-logging-format; please fix! G100,G101,G200,G201,G202 # these ignores are from flake8-simplify. please fix or ignore with commented reason diff --git a/.lintrunner.toml b/.lintrunner.toml index 8da7e961fe804d..759a75157fe4d4 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -35,7 +35,7 @@ init_command = [ '--dry-run={{DRYRUN}}', 'flake8==6.0.0', 'flake8-bugbear==23.3.23', - 'flake8-comprehensions==3.11.1', + 'flake8-comprehensions==3.12.0', 'flake8-executable==2.1.3', 'flake8-logging-format==0.9.0', 'flake8-pyi==23.3.1', diff --git a/test/jit/test_list_dict.py b/test/jit/test_list_dict.py index 25e90c0ea525d2..57b2281070b3f1 100644 --- a/test/jit/test_list_dict.py +++ b/test/jit/test_list_dict.py @@ -263,7 +263,7 @@ def fn(): def test_dict_keyword_with_mapping(self): def fn(): - return dict({"foo" : 1, "bar" : 2, "baz" : 3}) + return {"foo" : 1, "bar" : 2, "baz" : 3} self.checkScript(fn, ()) @@ -275,7 +275,7 @@ def fn(): def test_dict_keyword_with_dict_comprehension(self): def fn(): - return dict({i: chr(i + 65) for i in range(4)}) + return {i: chr(i + 65) for i in range(4)} self.checkScript(fn, ()) @@ -287,7 +287,7 @@ def fn(): def test_dict_keyword_with_empty_dict_comprehension(self): def fn(): - return dict({}) + return {} self.checkScript(fn, ()) diff --git a/test/test_datapipe.py b/test/test_datapipe.py index f7819b9adf108b..6d9a7d34c56389 100644 --- a/test/test_datapipe.py +++ b/test/test_datapipe.py @@ -2185,7 +2185,7 @@ def test_issubinstance(self): self.assertFalse(issubinstance(d, t[int])) # type: ignore[index] # dict - d = dict({'1': 1, '2': 2.}) + d = {'1': 1, '2': 2.} self.assertTrue(issubinstance(d, Dict)) self.assertTrue(issubinstance(d, Dict[str, T_co])) self.assertFalse(issubinstance(d, Dict[str, int])) diff --git a/torch/ao/pruning/_mappings.py b/torch/ao/pruning/_mappings.py index 281450bcb29eb7..726cbc6b0fc8af 100644 --- a/torch/ao/pruning/_mappings.py +++ b/torch/ao/pruning/_mappings.py @@ -5,14 +5,14 @@ def get_static_sparse_quantized_mapping(): import torch.ao.nn.sparse - _static_sparse_quantized_mapping = dict({ + _static_sparse_quantized_mapping = { torch.nn.Linear: torch.ao.nn.sparse.quantized.Linear, - }) + } return _static_sparse_quantized_mapping def get_dynamic_sparse_quantized_mapping(): import torch.ao.nn.sparse - _dynamic_sparse_quantized_mapping = dict({ + _dynamic_sparse_quantized_mapping = { torch.nn.Linear: torch.ao.nn.sparse.quantized.dynamic.Linear, - }) + } return _dynamic_sparse_quantized_mapping