github / github/codeql

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

Open
#8,714 5 comments 0 reactions 0 assignees View on GitHub
false-positive Python
Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 15h
Merged PRs (30d)
141

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.