pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.29k stars 1.13k forks source link

Spurious `no-name-in-module, import-error` with `py` #1536

Open adamtheturtle opened 7 years ago

adamtheturtle commented 7 years ago

Steps to reproduce

pip install pylint py

Create a file with the following content:

"""
Example file for pylint.
"""

from py.path import local

print(local('/etc/example.txt'))

Run pylint on this file.

Current behavior

no-name-in-module error is given. import-error is given.

Expected behavior

No error is given - this file works in Python.

pylint --version output

No config file found, using default configuration
pylint 1.7.1,
astroid 1.5.3
Python 3.6.1 (default, Apr  4 2017, 09:40:21)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)]
rogalski commented 7 years ago

Thanks for submitting an issue!

Namespace is populated automagically, we won't be able to infer it by generic mechanisms. To support this we would need astroid.brain hint.

Kilo59 commented 6 years ago

What's the recommended solution to deal with this issue?

PCManticore commented 6 years ago

@Kilo59 The recommended solution would be to provide a brain tip in astroid for this py module.

Here's an example for numpy: https://github.com/PyCQA/astroid/blob/master/astroid/brain/brain_numpy.py#L467. We'd need something similar for py, which should provide the members that pylint cannot currently infer due to how py it's being written. I'm not familiar with py, so if you have some time to work on a patch, that would be amazing.