-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
Description
Description of the false positive
LGTM complains that the raise exc_val
will raise a NoneType
(which would be wrong indeed). However, the type is actually exc_val: Optional[BaseException]
with a flag reraise_exc
indicating whether exc_val
is actually filled. The critical code section cannot be entered unless exc_val
actually contains a valid value.
A simplified version of the code in question (unrelated parts removed) looks like this. Note that reraise_exc
and exc_val
are always set together.
reraise_exc = False
exc_type = exc_val = tb = ...
for callback in callbacks:
try:
if callback(exc_type, exc_val, tb):
reraise_exc = False
exc_type = exc_val = tb = None
except BaseException as exc:
reraise_exc = True
exc_type, exc_val, tb = type(exc), exc, exc.__traceback__
if reraise_exc:
raise exc_val
URL to the alert on the project page on LGTM.com