Skip to content

Commit b11640c

Browse files
committed
Fix linting E722: do not use bare except
1 parent 03829fd commit b11640c

10 files changed

Lines changed: 15 additions & 18 deletions

File tree

_pytest/_code/code.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def __str__(self):
250250
line = str(self.statement).lstrip()
251251
except KeyboardInterrupt:
252252
raise
253-
except:
253+
except: # noqa
254254
line = "???"
255255
return " File %r:%d in %s\n %s\n" % (fn, self.lineno + 1, name, line)
256256

@@ -478,12 +478,12 @@ def _getindent(self, source):
478478
s = str(source.getstatement(len(source) - 1))
479479
except KeyboardInterrupt:
480480
raise
481-
except:
481+
except: # noqa
482482
try:
483483
s = str(source[-1])
484484
except KeyboardInterrupt:
485485
raise
486-
except:
486+
except: # noqa
487487
return 0
488488
return 4 + (len(s) - len(s.lstrip()))
489489

_pytest/_code/source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def findsource(obj):
254254
sourcelines, lineno = py.std.inspect.findsource(obj)
255255
except py.builtin._sysex:
256256
raise
257-
except:
257+
except: # noqa
258258
return None, -1
259259
source = Source()
260260
source.lines = [line.rstrip() for line in sourcelines]

_pytest/assertion/rewrite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def load_module(self, name):
210210
mod.__cached__ = pyc
211211
mod.__loader__ = self
212212
py.builtin.exec_(co, mod.__dict__)
213-
except:
213+
except: # noqa
214214
if name in sys.modules:
215215
del sys.modules[name]
216216
raise

_pytest/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def finish(self):
749749
try:
750750
func = self._finalizer.pop()
751751
func()
752-
except:
752+
except: # noqa
753753
exceptions.append(sys.exc_info())
754754
if exceptions:
755755
e = exceptions[0]

_pytest/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def wrap_session(config, doit):
118118
excinfo.typename, excinfo.value.msg))
119119
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
120120
session.exitstatus = EXIT_INTERRUPTED
121-
except:
121+
except: # noqa
122122
excinfo = _pytest._code.ExceptionInfo()
123123
config.notify_exception(excinfo, config.option)
124124
session.exitstatus = EXIT_INTERNALERROR
@@ -375,7 +375,7 @@ def _memoizedcall(self, attrname, function):
375375
res = function()
376376
except py.builtin._sysex:
377377
raise
378-
except:
378+
except: # noqa
379379
failure = sys.exc_info()
380380
setattr(self, exattrname, failure)
381381
raise

_pytest/python_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __eq__(self, actual):
8484

8585
try:
8686
actual = np.asarray(actual)
87-
except:
87+
except: # noqa
8888
raise TypeError("cannot compare '{0}' to numpy.ndarray".format(actual))
8989

9090
if actual.shape != self.expected.shape:

_pytest/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def __init__(self, func, when):
197197
except KeyboardInterrupt:
198198
self.stop = time()
199199
raise
200-
except:
200+
except: # noqa
201201
self.excinfo = ExceptionInfo()
202202
self.stop = time()
203203

_pytest/unittest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _addexcinfo(self, rawexcinfo):
115115
fail("".join(values), pytrace=False)
116116
except (fail.Exception, KeyboardInterrupt):
117117
raise
118-
except:
118+
except: # noqa
119119
fail("ERROR: Unknown Incompatible Exception "
120120
"representation:\n%r" % (rawexcinfo,), pytrace=False)
121121
except KeyboardInterrupt:

testing/code/test_excinfo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def reraise_me():
244244
def f(n):
245245
try:
246246
do_stuff()
247-
except:
247+
except: # noqa
248248
reraise_me()
249249

250250
excinfo = pytest.raises(RuntimeError, f, 8)
@@ -434,7 +434,7 @@ def excinfo_from_exec(self, source):
434434
exec(source.compile())
435435
except KeyboardInterrupt:
436436
raise
437-
except:
437+
except: # noqa
438438
return _pytest._code.ExceptionInfo()
439439
assert 0, "did not raise"
440440

@@ -1217,7 +1217,7 @@ def b(x):
12171217

12181218
try:
12191219
a(numpy_like())
1220-
except:
1220+
except: # noqa
12211221
from _pytest._code.code import ExceptionInfo
12221222
from _pytest.pytester import LineMatcher
12231223
exc_info = ExceptionInfo()
@@ -1241,7 +1241,7 @@ def __getattr__(self, attr):
12411241
return getattr(self, '_' + attr)
12421242

12431243
RecursionDepthError().trigger
1244-
except:
1244+
except: # noqa
12451245
from _pytest._code.code import ExceptionInfo
12461246
exc_info = ExceptionInfo()
12471247
if sys.version_info[:2] == (2, 6):

tox.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,3 @@ filterwarnings =
215215
[flake8]
216216
max-line-length = 120
217217
exclude = _pytest/vendored_packages/pluggy.py
218-
ignore=
219-
# do not use bare except'
220-
E722

0 commit comments

Comments
 (0)