Reputation: 595
If I do something like:
new_list = []
new_list.foo()
flake8 does not return an error for foo() method since it is not a 'list' method.
Is this normal or do I need to configure something?
Upvotes: 2
Views: 2892
Reputation: 36043
Flake8 is a wrapper around these tools:
- PyFlakes
- pep8
- Ned Batchelder’s McCabe script
PyFlakes is the part that you might expect to detect this type of error. But it detects very little, and it explains why:
Pyflakes is also faster than Pylint or Pychecker. This is largely because Pyflakes only examines the syntax tree of each file individually. As a consequence, Pyflakes is more limited in the types of things it can check.
The flake8 docs list the error codes provided by Pyflakes:
code sample message
F401 module imported but unused
F402 import module from line N shadowed by loop variable
F403 ‘from module import *’ used; unable to detect undefined names
F404 future import(s) name after other statements
F811 redefinition of unused name from line N
F812 list comprehension redefines name from line N
F821 undefined name name
F822 undefined name name in __all__
F823 local variable name ... referenced before assignment
F831 duplicate argument name in function definition
F841 local variable name is assigned to but never used
I second the recommendation for PyCharm, followed by PyLint.
Upvotes: 3
Reputation: 474161
flake8
does not handle the problem, but PyLint
does - issues the no-member
warning:
$ pylint test.py
No config file found, using default configuration
************* Module test
C: 1, 0: Missing module docstring (missing-docstring)
C: 1, 0: Invalid constant name "new_list" (invalid-name)
E: 2, 0: Instance of 'list' has no 'foo' member (no-member)
And, the built-in to PyCharm code analyzer would also warn about the unresolved attribute:
Upvotes: 6