github / github/codeql

LGTM.com - false positive when raising Optional guarded by flag

オープン
#3,066 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
false-positive Python
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

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

https://lgtm.com/projects/g/maxfischer2781/asyncstdlib/snapshot/0ad1b5599b80c4beae23cd5252c7a04203238fca/files/asyncstdlib/contextlib.py#x3f56861048e9ce14:1

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。