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.3k stars 1.13k forks source link

package.__path__ has incorrect type for namespace packages #3663

Open Optiligence opened 4 years ago

Optiligence commented 4 years ago

Steps to reproduce

mkdir package
echo 'import package
package.__path__._path' > test.py
/pylint test.py --errors-only

Current behavior

***** Module test test.py:2:0: E1101: Instance of 'list' has no '_path' member (no-member)

Expected behavior

no error

pylint --version output

pylint 2.5.2 astroid 2.4.1 Python 3.8.2 | packaged by conda-forge | (default, Mar 23 2020, 18:16:37) [GCC 7.3.0]

brycepg commented 4 years ago

@Optiligence From what packages I imported, the error is working as intended. What package does this false positive occur for you? They may be improperly setting __path__ to a non-list data type.

Python 3.8.2 (default, Mar  4 2020, 00:07:26) 
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pylint
>>> pylint.__path__
['/home/user/Documents/pylint-issues/issue-3663/env/lib/python3.8/site-packages/pylint']
>>> type(pylint.__path__)
<class 'list'>
Optiligence commented 4 years ago

see the reproduction steps given above

Optiligence commented 4 years ago

in practice it’s a subpackage of another package, it has no __init__.py

brycepg commented 4 years ago

My bad @Optiligence. I see now this applies to namespace packages

brycepg commented 4 years ago

The relevant line of code occurs here: https://github.com/PyCQA/astroid/blob/master/astroid/interpreter/objectmodel.py#L147

astroid should use the _NamespacePackage class node instead of a list` class node when the module is a namespace package.