Skip to content

Commit 299ea84

Browse files
xuhdevfacebook-github-bot
authored andcommittedJun 25, 2019
Use latest stable flake8-bugbear in CI and fix B011 flake8 error. (pytorch#21944)
Summary: - PyCQA/flake8-bugbear#53 has been fixed (but not yet closed on their side) and a new version of flake8-bugbear has been released on Mar 28, 2019. Switch CI to use the latest stable version. - Fix the new B011 errors that flake8-bugbear catches in the current codebase. --- B011: Do not call assert False since python -O removes these calls. Instead callers should raise AssertionError(). Pull Request resolved: pytorch#21944 Differential Revision: D15974842 Pulled By: soumith fbshipit-source-id: de5c2c07015f7f1c50cb3904c651914b8c83bf5c
1 parent f5df0c9 commit 299ea84

File tree

9 files changed

+12
-14
lines changed

9 files changed

+12
-14
lines changed
 

‎.travis.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ matrix:
3636
dist: xenial # required for Python 3.7 (travis-ci/travis-ci#9069)
3737
sudo: required # required for Python 3.7 (travis-ci/travis-ci#9069)
3838
install:
39-
- pip install flake8 flake8-mypy flake8-comprehensions flake8-pyi mccabe pycodestyle pyflakes
40-
# Apparently Facebook runs master of this one
41-
# https://github.com/PyCQA/flake8-bugbear/issues/53
42-
- pip install git+https://github.com/PyCQA/flake8-bugbear.git@d9444713a51a9fb6ee8cd2d88fca85e9ff0c2d58
39+
- pip install flake8 flake8-bugbear flake8-mypy flake8-comprehensions flake8-pyi mccabe pycodestyle pyflakes
4340
script: flake8
4441
- name: "MyPy typecheck"
4542
python: "3.6"

‎CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ which is in PyTorch's `requirements.txt`.
548548

549549
### Pre-commit Tidy/Linting Hook
550550

551-
We use clang-tidy and flake8 (installed with flake-mypy) to perform additional
551+
We use clang-tidy and flake8 (installed with flake8-bugbear,
552+
flake8-comprehensions, flake8-mypy, and flake8-pyi) to perform additional
552553
formatting and semantic checking of code. We provide a pre-commit git hook for
553554
performing these checks, before a commit is created:
554555

‎aten/src/ATen/common_with_cwrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def parse_arguments(args):
1818
del arg['arg']
1919
new_args.append(arg)
2020
else:
21-
assert False
21+
raise AssertionError()
2222
return new_args
2323

2424

‎test/error_messages/storage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def check_error(desc, fn, *required_substrings):
1414
for sub in required_substrings:
1515
assert sub in error_message
1616
return
17-
assert False, "given function ({}) didn't raise an error".format(desc)
17+
raise AssertionError("given function ({}) didn't raise an error".format(desc))
1818

1919
check_error(
2020
'Wrong argument types',

‎test/onnx/test_operators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class MyFun(Function):
218218
def symbolic(g, x):
219219
# The inside of this function should never be invoked, because
220220
# we will fail due to an argument mismatch first.
221-
assert False
221+
raise AssertionError()
222222

223223
@staticmethod
224224
def forward(ctx, x, y):

‎test/onnx/verify.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def run(args):
431431
# that is a bug in verify
432432
errs.requireEqual(proto, alt_proto)
433433
errs.requireEqual(proto_bytes.getvalue(), alt_proto_bytes.getvalue())
434-
assert False
434+
raise AssertionError()
435435

436436
# TODO: test that the traced model also returns the same thing...
437437
run_helper(torch_out, args)

‎test/test_nn.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7354,7 +7354,7 @@ def get_grid(device='cpu', data=None):
73547354
[[3.4500, 6.0000000000, 5.0000, 4.8340, 9.0000],
73557355
[2.2500, 6.3332500450, 5.0000, 5.1000, 7.7500]]).view(1, 1, 2, 5)
73567356
else:
7357-
assert False, "missing groundtruth test for padding mode '{}'".format(padding_mode)
7357+
raise AssertionError("missing groundtruth test for padding mode '{}'".format(padding_mode))
73587358
elif mode == 'nearest':
73597359
if padding_mode == 'zeros':
73607360
groundtruth = torch.tensor(
@@ -7369,9 +7369,9 @@ def get_grid(device='cpu', data=None):
73697369
[[1., 8., 5., 7., 9.],
73707370
[1., 8., 5., 8., 9.]]).view(1, 1, 2, 5)
73717371
else:
7372-
assert False, "missing groundtruth test for padding mode '{}'".format(padding_mode)
7372+
raise AssertionError("missing groundtruth test for padding mode '{}'".format(padding_mode))
73737373
else:
7374-
assert False, "missing groundtruth test for interpolation mode '{}'".format(mode)
7374+
raise AssertionError("missing groundtruth test for interpolation mode '{}'".format(mode))
73757375
output = F.grid_sample(input, grid, mode=mode, padding_mode=padding_mode)
73767376
self.assertEqual(output, groundtruth,
73777377
"groundtruth comparison failed for mode={}, "

‎tools/autograd/gen_variable_type.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def guard_for(arg):
588588
if arg['name'] == derivative_var_name:
589589
break
590590
else:
591-
assert False
591+
raise AssertionError()
592592

593593
return 'grad_fn->should_compute_output({})'.format(edge_off)
594594

‎tools/cwrap/cwrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def parse_arguments(self, args):
130130
del arg['arg']
131131
new_args.append(arg)
132132
else:
133-
assert False
133+
raise AssertionError()
134134
return new_args
135135

136136
def search_plugins(self, fnname, args, fallback):

0 commit comments

Comments
 (0)