-
-
Couldn't load subscription status.
- Fork 960
Closed
Labels
Description
# sscce.py
import git
git.Repo(".").tags[None]$ git init
Initialized empty Git repository in /tmp/tmp.Xoz9gZndOi/.git/
$ venv/bin/python sscce.py
Traceback (most recent call last):
File "sscce.py", line 5, in <module>
git.Repo(".").tags[None]
File "/tmp/tmp.Xoz9gZndOi/venv/lib/python3.8/site-packages/git/util.py", line 1087, in __getitem__
assert isinstance(index, (int, str, slice)), "Index of IterableList should be an int or str"
AssertionError: Index of IterableList should be an int or strLine 1087 in c84dde2
| assert isinstance(index, (int, str, slice)), "Index of IterableList should be an int or str" |
assert should not be used in product code because it can be ignored with -O:
$ venv/bin/python -O sscce.py
Traceback (most recent call last):
File "sscce.py", line 5, in <module>
git.Repo(".").tags[None]
File "/tmp/tmp.Xoz9gZndOi/venv/lib/python3.8/site-packages/git/util.py", line 1095, in __getitem__
return getattr(self, index)
TypeError: getattr(): attribute name must be string(In fact, that behavior is probably better since a TypeError is more semantically meaningful.)
bandit can catch this kind of thing:
$ venv/bin/bandit venv/lib/python3.8/site-packages/git/util.py
...
>> Issue: [B101:assert_used] Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Severity: Low Confidence: High
CWE: CWE-703 (https://cwe.mitre.org/data/definitions/703.html)
Location: venv/lib/python3.8/site-packages/git/util.py:1087:8
More Info: https://bandit.readthedocs.io/en/1.7.4/plugins/b101_assert_used.html
1086
1087 assert isinstance(index, (int, str, slice)), "Index of IterableList should be an int or str"
1088
1089 if isinstance(index, int):
...