[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
This commit is contained in:
Aaron Gokaslan
2023-04-15 15:33:42 +00:00
committed by PyTorch MergeBot
parent 506bd05752
commit 85f38b8a33
5 changed files with 10 additions and 10 deletions

View File

@ -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

View File

@ -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',

View File

@ -263,7 +263,7 @@ class TestList(JitTestCase):
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 @@ class TestList(JitTestCase):
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 @@ class TestList(JitTestCase):
def test_dict_keyword_with_empty_dict_comprehension(self):
def fn():
return dict({})
return {}
self.checkScript(fn, ())

View File

@ -2185,7 +2185,7 @@ class TestTyping(TestCase):
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]))

View File

@ -5,14 +5,14 @@ __all__ = [
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