Nealium
Nealium

Reputation: 2268

flake8 & pycodestyle/pep8 not showing E721 errors

Versions
λ python --version
Python 3.10.6

λ flake8 --version
5.0.4 (mccabe: 0.7.0, pycodestyle: 2.9.1, pyflakes: 2.5.0) CPython 3.10.6 on Linux 
# and on Windows

## Edit: after update
λ flake8 --version
6.0.0 (mccabe: 0.7.0, pycodestyle: 2.10.0, pyflakes: 3.0.1) CPython 3.10.6 on Linux
Error to Catch
Example (test.py)
test = []
if type(test) == list:
    print('test is a list')
else:
    print('test not a list')

Both flake8 test.py & pycodestyle test.py commands, in terminal, do not show any errors. Yet they should.
I have no extra config, from what I'm reading this error should be enabled by default; Per pycodestyle 2.9.1 Docs

I've also tried:

Am I missing something?- I quite like this error and now I'm worried it's not catching other errors as well.

Upvotes: -2

Views: 558

Answers (1)

Nealium
Nealium

Reputation: 2268

Hopefully this will help somebody in the future.

This is proper behavior, the Docs do not correctly describe the error

Per this comment in the source code:

# Allow comparison for types which are not obvious
  • Location: pycodestyle.py, comparison_type(), line 1436 in version 2.10.0

obvious types are:

SINGLETONS = frozenset(['False', 'None', 'True'])
  • Location: pycodestyle.py, line 104 in version 2.10.0

Their Doc example of if type(user) == User: is not obvious and therefor wouldn't trigger it

Examples

test = []
print(type(test) == list)         # Pass
print(type(test) == type(list))   # Pass
print(type(test) == type(float))  # Pass
print(type(test) == type(None))   # Fail
print(type(test) == type(True))   # Fail

I presume some Linters, possible pylint, does not work like this- thus my confusion, as I saw this error while using pylsp-all in Vim

Upvotes: -1

Related Questions