pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Invalid call of a module in subdirectory not detected

Open pylint-bot opened this issue 10 years ago • 2 comments

Originally reported by: Pavel Roskin (BitBucket: pavel_roskin)


Python 2 or 3 cannot run this file:

import xml
xml.etree.ElementTree.parse('test.xml')

xml.etree.ElementTree should be imported, not xml

#!shell
$ python3 test.py 
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    xml.etree.ElementTree.parse('test.xml')
AttributeError: 'module' object has no attribute 'etree'

But pylint only complains about missing module docstring. But change "parse" to "pares", and pylint notices that:

C:  1, 0: Missing module docstring (missing-docstring)
E:  2, 0: Module 'xml.etree.ElementTree' has no 'pares' member (no-member)

Apparently, pylint can read the module and its members, but cannot detect that the module is imported incorrectly.


  • Bitbucket: https://bitbucket.org/logilab/pylint/issue/666

pylint-bot avatar Oct 11 '15 06:10 pylint-bot

Original comment by Pavel Roskin (BitBucket: pavel_roskin):


I was able to reproduce the issue without involving any external modules.

echo -e "import foo\nfoo.bar.baz()" >test.py
mkdir foo
touch foo/__init__.py
mkdir foo/bar
echo -e "def baz():\n    pass" >foo/bar/__init__.py
pylint test.py

pylint thinks that foo.bar.baz() can be called, but python disagrees.

pylint-bot avatar Oct 15 '15 06:10 pylint-bot

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Thanks! This can definitely be fixed at some point.

pylint-bot avatar Oct 15 '15 10:10 pylint-bot