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
- https://www.flake8rules.com/rules/E721.html
- No:
type(user) == User
- Do:
isinstance(user, User)
- No:
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
- unless disabled per line with
# noqa
I've also tried:
{flake8|pycodestyle} --select E721 test.py
to explicitly select the error{flake8|pycodestyle} --ignore E302 test.py
to clear the default ignore list{flake8|pycodestyle} --ignore E302 --select E721 test.py
Am I missing something?- I quite like this error and now I'm worried it's not catching other errors as well.
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:
obvious
types are:Their Doc example of
if type(user) == User:
is not obvious and therefor wouldn't trigger itExamples
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