I am running PyLint on a Python project. PyLint makes many complaints about being unable to find numpy members. How can I avoid this while avoiding skipping membership check
In recent versions of pylint you can add --extension-pkg-whitelist=numpy
to your pylint command. They had fixed this problem in an earlier version in an unsafe way. Now if you want them to look more carefully at a package outside of the standard library, you must explicitly whitelist it. See here.
This has finally been resolved in Pylint 1.8.2. Works out of the box, no pylintrc tweaks needed!
I had the same issue here, even with the latest versions of all related packages (astroid 1.3.2
, logilab_common 0.63.2
, pylon 1.4.0
).
The following solution worked like a charm: I added numpy
to the list of ignored modules by modifying my pylintrc
file, in the [TYPECHECK]
section:
[TYPECHECK]
ignored-modules = numpy
Depending on the error, you might also need to add the following line (still in the [TYPECHECK] section
):
ignored-classes = numpy
I had this problem with numpy, scipy, sklearn, nipy, etc., and I solved it by wrapping epylint like so:
$ cat epylint.py
#!/usr/bin/python
"""
Synopsis: epylint wrapper that filters a bunch of false-positive warnings and errors
Author: DOHMATOB Elvis Dopgima <gmdopp@gmail.com> <elvis.dohmatob@inria.fr>
"""
import os
import sys
import re
from subprocess import Popen, STDOUT, PIPE
NUMPY_HAS_NO_MEMBER = re.compile("Module 'numpy(?:\..+)?' has no '.+' member")
SCIPY_HAS_NO_MEMBER = re.compile("Module 'scipy(?:\..+)?' has no '.+' member")
SCIPY_HAS_NO_MEMBER2 = re.compile("No name '.+' in module 'scipy(?:\..+)?'")
NIPY_HAS_NO_MEMBER = re.compile("Module 'nipy(?:\..+)?' has no '.+' member")
SK_ATTR_DEFINED_OUTSIDE_INIT = re.compile("Attribute '.+_' defined outside __init__")
REL_IMPORT_SHOULD_BE = re.compile("Relative import '.+', should be '.+")
REDEFINING_NAME_FROM_OUTER_SCOPE = re.compile("Redefining name '.+' from outer scope")
if __name__ == "__main__":
basename = os.path.basename(sys.argv[1])
for line in Popen(['epylint', sys.argv[1], '--disable=C,R,I' # filter thesew arnings
], stdout=PIPE, stderr=STDOUT, universal_newlines=True).stdout:
if line.startswith("***********"):
continue
elif line.startswith("No config file found,"):
continue
elif "anomalous-backslash-in-string," in line:
continue
if NUMPY_HAS_NO_MEMBER.search(line):
continue
if SCIPY_HAS_NO_MEMBER.search(line):
continue
if SCIPY_HAS_NO_MEMBER2.search(line):
continue
if "Used * or ** magic" in line:
continue
if "No module named" in line and "_flymake" in line:
continue
if SK_ATTR_DEFINED_OUTSIDE_INIT.search(line):
continue
if "Access to a protected member" in line:
continue
if REL_IMPORT_SHOULD_BE.search(line):
continue
if REDEFINING_NAME_FROM_OUTER_SCOPE.search(line):
continue
if NIPY_HAS_NO_MEMBER.search(line):
continue
# XXX extend by adding more handles for false-positives here
else:
print line,
This script simply runs epylint, then scrapes its output to filter out false-positive warnings and errors. You can extend it by added more elif cases.
N.B.: If this applies to you, then you'll want to modify your pychechers.sh so it likes like this
#!/bin/bash
epylint.py "$1" 2>/dev/null
pyflakes "$1"
pep8 --ignore=E221,E701,E202 --repeat "$1"
true
(Of course, you have to make epylint.py executable first)
Here is a link to my .emacs https://github.com/dohmatob/mydotemacs. Hope this is useful to someone.
I had to add this at the top of any file where I use numpy a lot.
# To ignore numpy errors:
# pylint: disable=E1101
Just in case someone in eclipse is having trouble with Pydev and pylint...
This seems to work on at least Pylint 1.1.0:
[TYPECHECK]
ignored-classes=numpy