github / github/codeql

[Python] False positive py/unreachable-statement with global variable

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

Description

**Description of the false positive**

A global variable is set (`t = None`) at the top of the file. Cleanup code checks `if t is not None`, and LGTM marks the code inside this branch unreachable. However, there is a method containing a `global t` statement, allowing it to reassign the global variable, which it does.

#1268 appears to be similar, but with the `nonlocal` statement in place of `global`.

**URL to the alert on the project page on LGTM.com**

https://lgtm.com/projects/g/h5py/h5py/snapshot/9722123a723cd6299d1f7470e0f789080ec18e23/files/examples/threading_example.py?sort=name&dir=ASC&mode=heatmap#xe2a68c5ef5581699:1

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.