[code-quality] pylint import succeeds or fails depending on a previous import statement
Alexey Bashtanov
bashtanov at imap.cc
Wed Jan 24 06:14:13 EST 2018
Hello,
I came across the following problem with pylint: a import from a local
directory works only if there's some `from ... import ...` statement above.
My code is organized as follows:
~/pylinttest/
foo/
bar.py
baz.py
qux.py
__init__.py
.pylintrc
bar.py contains the following code:
from urllib import request
import qux
baz.py contains the following code:
import qux
Here are the results of running pylint:
alexey at ev9d9:~/pylinttest$ pylint foo.bar
Using config file /home/alexey/pylinttest/.pylintrc
************* Module foo.bar
W: 1, 0: Unused request imported from urllib (unused-import)
W: 2, 0: Unused import qux (unused-import)
alexey at ev9d9:~/pylinttest$ pylint foo.baz
Using config file /home/alexey/pylinttest/.pylintrc
************* Module foo.baz
E: 1, 0: Unable to import 'qux' (import-error)
W: 1, 0: Unused import qux (unused-import)
Why does it fail to load qux only if there was no from-import statement
before?
Changing urllib.request to e.g. collections.deque does not make a
difference.
My pylint version is 1.1.0, and it can be reproduced both with python
2.7.5 and 3.4.0
Regards,
Alexey
More information about the code-quality
mailing list