github / github/codeql

LGTM.com - false positive `unreachable statement` for numpy boolean conversion

未關閉
#8,714 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
false-positive Python
主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 15 小時
30 天內合併 PR
141

描述

Consider this scenario:
```python
import numpy as np
cond = np.arange(25) < 5
try:
less_than_5 = bool(cond)
except ValueError:
less_than_5 = False
```
The `try` block is necessary, since array comparisons by definition raise `ValueError`s. This is certainly not an "unreachable statement". Am I missing something?

**URL to the alert on the project page on LGTM.com**
https://lgtm.com/projects/g/ntjess/s3a/snapshot/8565aa0f07a734d5b92e29b61cd3e6169e67f704/files/s3a/models/tablemodel.py?sort=name&dir=ASC&mode=heatmap#L77

貢獻指南

開啟貢獻指南

研究方向

Open the linked LGTM alert and compare it with the Python reproducer, then locate the CodeQL query responsible for the `unreachable statement` alert. Verify how the analysis handles `bool(cond)` when the NumPy array conversion can raise `ValueError`, and use the relevant query coverage to confirm the false positive is resolved.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
numpy, python
領域
devtools
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。