Search code examples
pythonpylint

Why is pylint unable to find this package's module(s)?


I'm currently working with pylint, and I'm getting an error when I lint the single file (repro below). I'm using the azure sdk, but that is just the package I'm referencing, that shouldn't be significant here.

Repro

$ mkdir pylinttesting && cd pylinttesting
$ python3 -m venv venv
$ . venv/bin/activate
$ pip3 install azure==2.0.0rc6
$ echo 'from azure import mgmt' > app.py

Running this script file causes no issues (python3 app.py)

pylint output

Even though this is totally valid and runs/imports without error, pylint still complains about it. Relevant output below (cut down for brevity)...

E:  1, 0: No name 'mgmt' in module 'azure' (no-name-in-module)

External dependencies
---------------------
::

    azure (app)

But! If I run this little snippet (in the same virtual environment)...

import os
import pkgutil
import azure

package_path = os.path.dirname(azure.__file__)
[print(name) for _, name, _ in pkgutil.iter_modules([package_path])]

... I get the following output...

batch
common
mgmt
servicebus
servicemanagement
storage

So obviously the mgmt module lives in the azure package. But I'm wondering why pylint doesn't pick that up?

It's also worth noting that if I do from azure import common (common is another module in the package), pylint doesn't throw the error.

Any thoughts on why pylint may be unhappy with this mgmt module in the package?

EDIT: pylint version information...

pylint 1.6.5, 
astroid 1.4.9
Python 3.6.0 (default, Dec 24 2016, 00:01:50) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]

Solution

  • You are using Pylint version that does not (yet) support declare_namespace for creating namespaces. What are the version of pylint/astroid used by you?

    See https://github.com/PyCQA/pylint/issues/687 for similar issue and link to code which supports this namespace creation.

    Keep in mind that Pylint actually does not run Python code during analysis, so most of non-standard (non-inferable) constructs have to be supported by writing custom code.