An erroneous error occurs when a file is named "config.py".
> tree pylint-experiment/
pylint-experiment/
└── example
├── config.py
└── foo.py
> cat pylint-experiment/example/foo.py
import config
print(config.VARIABLE)
> cat pylint-experiment/example/config.py
VARIABLE = 1
pylint --errors-only pylint-experiment/************* Module some_dir.other
pylint-experiment/some_dir/other.py:3:6: E1101: Module 'config' has no 'VARIABLE' member (no-member)
I expect to see:
************* Module example.foo
pylint-experiment/example/foo.py:1:0: E0401: Unable to import 'config' (import-error)
This is what happens if I rename config to bar and change import config to import bar.
pylint 2.0.0.dev2
astroid 2.0.0.dev4
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)]
~This is working as intended since you are specifying a namespace/package to lint (since a folder is automatically a namespace package in python3). Python3 does not support relative imports for packages, so you see the error above.~
~You can see this in action with the python repl:~
cd pylint-experiment
python
> from example import foo
ModuleNotFoundError: No module named 'config'
~If you want to lint your script, foo.py, run pylint pylint-experiment/example/foo.py~
@brycepg I expected the import-error, as per "Expected behavior", but instead there is a no-member error, which happens when the file is named config.py.
That is, I'd expect the same error from both of these:
> pylint -E pylint-experiment-changed-names/
************* Module example.foo
pylint-experiment-changed-names/example/foo.py:1:0: E0401: Unable to import 'bar' (import-error)
> pylint -E pylint-experiment
************* Module example.foo
pylint-experiment/example/foo.py:3:6: E1101: Module 'config' has no 'VARIABLE' member (no-member)
Where pylint-experiment-changed-names/ is the same as the given example, but with config.py renamed to bar.py and the import in foo.py changed accordingly.
Oh my bad, you're right. This also applies to explicit packages
So the super silly bug is that if your file is named config.py, then pylint imports its own config.py file:
In [3]: owner.file # where owner is the module that raised the error
Out[3]: '/Users/claudiu/projects/personal/pylint/pylint/config.py'
In [4]: owner.path
Out[4]: ['/Users/claudiu/projects/personal/pylint/pylint/config.py']
I bet the same happens for all the files in the pylint directory.
I'm experiencing what I think is a similar issue, tested with pylint version 1.9.3 and 2.0.1.
Given the following setup,
config package:$ tree config/
config/
└── subpackage
└── __init__.py
message package:$ tree message/
message/
└── subpackage
└── __init__.py
very_custom_package package:$ tree very_custom_package/
very_custom_package/
└── subpackage
└── __init__.py
$ tree tests/
tests/
├── __init__.py
└── test_packages.py
$ cat tests/test_packages.py
"""Notice we get errors for `message` & `config`, but not `very_custom_package`."""
import config.subpackage
import message.subpackage
import very_custom_package.subpackage
print(config.subpackage.desc)
print(message.subpackage.desc)
print(very_custom_package.subpackage.desc)
If I run pylint tests/ (checked with both 1.9.3 and 2.0.1), I get erroneous complaints about the config and message packages, but not very_custom_package.
$ pylint tests/
No config file found, using default configuration
************* Module tests.test_packages
E: 2, 0: No name 'subpackage' in module 'config' (no-name-in-module)
E: 3, 0: No name 'subpackage' in module 'message' (no-name-in-module)
E: 6, 6: Module 'config' has no 'subpackage' member (no-member)
E: 7, 6: Module 'message' has no 'subpackage' member (no-member)
$ pylint tests/
************* Module tests.test_packages
tests/test_packages.py:2:0: E0611: No name 'subpackage' in module 'config' (no-name-in-module)
tests/test_packages.py:3:0: E0611: No name 'subpackage' in module 'message' (no-name-in-module)
tests/test_packages.py:6:6: E1101: Module 'config' has no 'subpackage' member (no-member)
tests/test_packages.py:7:6: E1101: Module 'message' has no 'subpackage' member (no-member)
No errors for the message and config packages, like the very_custom_package package.
__init__.py resolves the false-positive, but isn't desirable.config -> zconfig) results in the errors going away, so somehow the specific names matter & it's not related to the package being named with underscores.