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.31k stars 1.14k forks source link

Relative imports not properly parsed #2222

Open jyn514 opened 6 years ago

jyn514 commented 6 years ago

Steps to reproduce

  1. mkdir package
  2. echo > package/module.py
  3. echo "from .module import *" > package/__init__.py
  4. echo "from package import *; print(module)" > package/test.py
  5. pylint package --errors-only

Current behavior

No config file found, using default configuration
************* Module package.test
E:  1,29: Undefined variable 'module' (undefined-variable)

Expected behavior

No config file found, using default configuration

pylint --version output

No config file found, using default configuration
pylint 1.9.2, 
astroid 1.6.5
Python 3.6.5 (default, Apr  4 2018, 15:01:18) 
[GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]

I think what's going on is that normally package/module would not be imported and give a name error, but because it's imported in __init__, it's part of the package namespace. This is edge behaviour and probably not something that should be depended on in production.

PCManticore commented 6 years ago

Thanks for the report! This definitely feels to be an edge case, but we should still handle it.