How do I get PyLint to recognize numpy members?

前端 未结 22 880
南旧
南旧 2020-11-28 20:29

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

相关标签:
22条回答
  • 2020-11-28 21:01

    A quick answer: update Pylint to 1.7.1 (use conda-forge provided Pylint 1.7.1 if you use conda to manage packages)

    I found a similar issue in pylint GitHub here and someone replied everything getting OK after updating to 1.7.1.

    0 讨论(0)
  • 2020-11-28 21:02

    Since this is the top result in google and it gave me the impression that you have to ignore those warnings in all files:

    The problem has actually been fixed in the sources of pylint/astroid last month https://bitbucket.org/logilab/astroid/commits/83d78af4866be5818f193360c78185e1008fd29e but are not yet in the Ubuntu packages.

    To get the sources, just

    hg clone https://bitbucket.org/logilab/pylint/
    hg clone https://bitbucket.org/logilab/astroid
    mkdir logilab && touch logilab/__init__.py
    hg clone http://hg.logilab.org/logilab/common logilab/common
    cd pylint && python setup.py install
    

    whereby the last step will most likely require a sudo and of course you need mercurial to clone.

    0 讨论(0)
  • 2020-11-28 21:04

    In Extension to j_hougs answer, you can now add the modules in question to this line in .pylintrc, which is already prepared empty on generation:

    extension-pkg-whitelist=numpy
    

    you can generate a sample .pylintrc by doing:

    pylint --generate-rcfile > .pylintrc
    

    and then edit the mentioned line

    0 讨论(0)
  • 2020-11-28 21:05

    I've been working on a patch to pylint to solve the issue with dynamic members in libraries such as numpy. It adds a "dynamic-modules" option which forces to check if members exist during runtime by making a real import of the module. See Issue #413 in logilab/pylint. There is also a pull request, see link in one of the comments.

    0 讨论(0)
提交回复
热议问题