github / github/codeql

LGTM.com - false positive `unhashable` alert indexing list with slice

Open
#8,711 3 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 the following example (reduced version of the actual alert):
```python
def access_one_or_all(one=False):
if one:
accessor = 0
else:
accessor = slice(None)
mylist = [1,2,3]
return mylist[accessor]
```
This is valid python code, but LGTM gives me the following alert:
`This instance of slice is unhashable.`

**URL to the alert on the project page on LGTM.com**
https://lgtm.com/projects/g/ntjess/s3a/snapshot/8565aa0f07a734d5b92e29b61cd3e6169e67f704/files/s3a/compio/helpers.py#L61

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.