python code checks
Some code checks I do while reviewing python code.
# Using [] instead of generator expressions
grep -rn --exclude-dir=venv --include="*.py" '\(sum\|min\|max\|any\|all\|list\|tuple\|set\)(\[.*\])' .
# Using range(len(...)) instead of enumerate()
grep -rn --exclude-dir=venv --include="*.py" 'for .* in range(len(.*))' .
# Using == to compare with None, True, False instead of is
grep -rn --exclude-dir=venv --include="*.py" -E '== *(None|True|False)' .
# Using + to concatenate strings in a loop
grep -rn --exclude-dir=venv --include="*.py" -E 'for .* in .*:\n.*\+= *' .
# Iterating over a dictionary with for key in dict.keys()
grep -rn --exclude-dir=venv --include="*.py" 'for .* in .*\.keys()' .
16. Sep 2024