Replace bare `except`s with `except BaseException`

Mostly I wanted to remove uses of `noqa`.

In Python 3 the two are the same.
This commit is contained in:
Ran Benita 2020-04-24 22:15:45 +03:00
parent d1534181c0
commit 59a12e9ab3
6 changed files with 9 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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