Replace bare excepts with except BaseException
Mostly I wanted to remove uses of `noqa`. In Python 3 the two are the same.
This commit is contained in:
@@ -277,7 +277,7 @@ class TracebackEntry:
|
||||
line = str(self.statement).lstrip()
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
except: # noqa
|
||||
except BaseException:
|
||||
line = "???"
|
||||
return " File %r:%d in %s\n %s\n" % (fn, self.lineno + 1, name, line)
|
||||
|
||||
@@ -667,12 +667,12 @@ class FormattedExcinfo:
|
||||
s = str(source.getstatement(len(source) - 1))
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
except: # noqa
|
||||
except BaseException:
|
||||
try:
|
||||
s = str(source[-1])
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
except: # noqa
|
||||
except BaseException:
|
||||
return 0
|
||||
return 4 + (len(s) - len(s.lstrip()))
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ def wrap_session(
|
||||
)
|
||||
config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
|
||||
session.exitstatus = exitstatus
|
||||
except: # noqa
|
||||
except BaseException:
|
||||
session.exitstatus = ExitCode.INTERNAL_ERROR
|
||||
excinfo = _pytest._code.ExceptionInfo.from_current()
|
||||
try:
|
||||
|
||||
@@ -123,7 +123,7 @@ class ApproxNumpy(ApproxBase):
|
||||
if not np.isscalar(actual):
|
||||
try:
|
||||
actual = np.asarray(actual)
|
||||
except: # noqa
|
||||
except BaseException:
|
||||
raise TypeError("cannot compare '{}' to numpy.ndarray".format(actual))
|
||||
|
||||
if not np.isscalar(actual) and actual.shape != self.expected.shape:
|
||||
|
||||
@@ -258,7 +258,7 @@ class CallInfo:
|
||||
precise_start = perf_counter()
|
||||
try:
|
||||
result = func()
|
||||
except: # noqa
|
||||
except BaseException:
|
||||
excinfo = ExceptionInfo.from_current()
|
||||
if reraise is not None and excinfo.errisinstance(reraise):
|
||||
raise
|
||||
|
||||
@@ -151,7 +151,7 @@ class TestCaseFunction(Function):
|
||||
fail("".join(values), pytrace=False)
|
||||
except (fail.Exception, KeyboardInterrupt):
|
||||
raise
|
||||
except: # noqa
|
||||
except BaseException:
|
||||
fail(
|
||||
"ERROR: Unknown Incompatible Exception "
|
||||
"representation:\n%r" % (rawexcinfo,),
|
||||
|
||||
@@ -239,7 +239,7 @@ class TestTraceback_f_g_h:
|
||||
def f(n: int) -> None:
|
||||
try:
|
||||
do_stuff()
|
||||
except: # noqa
|
||||
except BaseException:
|
||||
reraise_me()
|
||||
|
||||
excinfo = pytest.raises(RuntimeError, f, 8)
|
||||
@@ -445,7 +445,7 @@ class TestFormattedExcinfo:
|
||||
exec(source.compile())
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
except: # noqa
|
||||
except BaseException:
|
||||
return _pytest._code.ExceptionInfo.from_current()
|
||||
assert 0, "did not raise"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user