summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2018-03-30 10:42:16 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2018-03-30 10:43:33 +0200
commit7f46f9341cc54bbe6763409c4ca7ea3adfec098a (patch)
tree55b39e14fc8693bb7211d5c28298596676738258
parent75b6c1a333baffa70e29a42d43650aa7bc331b4d (diff)
downloadastroid-git-7f46f9341cc54bbe6763409c4ca7ea3adfec098a.tar.gz
Module.__path__ is now a list
It used to be a string containing the path, but it doesn't reflect the situation on Python, where it is actually a list. Also fix a bug with namespace package's __path__ attribute, which wasn't using the module's __path__, but its file attribute, which is None for namespace packages. Close #528
-rw-r--r--ChangeLog10
-rw-r--r--astroid/interpreter/objectmodel.py11
-rw-r--r--astroid/rebuilder.py3
-rw-r--r--astroid/scoped_nodes.py7
4 files changed, 25 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index de01f065..f828242b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,16 @@ Change log for the astroid package (used to be astng)
=====================================================
--
+
+ * Module.__path__ is now a list
+
+ It used to be a string containing the path, but it doesn't reflect the situation
+ on Python, where it is actually a list.
+
+ * Fix a bug with namespace package's __path__ attribute.
+
+ Close #528
+
* Added brain tips for random.sample
Part of PyCQA/pylint#811
diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py
index 096a8939..bae60fc5 100644
--- a/astroid/interpreter/objectmodel.py
+++ b/astroid/interpreter/objectmodel.py
@@ -127,11 +127,16 @@ class ModuleModel(ObjectModel):
raise exceptions.AttributeInferenceError(target=self._instance,
attribute='__path__')
- path = os.path.dirname(self._instance.file)
- path_obj = node_classes.Const(value=path, parent=self._instance)
+ path_objs = [
+ node_classes.Const(
+ value=path if not path.endswith('__init__.py') else os.path.dirname(path),
+ parent=self._instance
+ )
+ for path in self._instance.path
+ ]
container = node_classes.List(parent=self._instance)
- container.postinit([path_obj])
+ container.postinit(path_objs)
return container
diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py
index a323e972..5d4ffcff 100644
--- a/astroid/rebuilder.py
+++ b/astroid/rebuilder.py
@@ -125,7 +125,8 @@ class TreeRebuilder(object):
def visit_module(self, node, modname, modpath, package):
"""visit a Module node by returning a fresh instance of it"""
node, doc = _get_doc(node)
- newnode = nodes.Module(name=modname, doc=doc, file=modpath, path=modpath,
+ newnode = nodes.Module(name=modname, doc=doc, file=modpath,
+ path=[modpath],
package=package, parent=None)
newnode.postinit([self.visit(child, newnode) for child in node.body])
return newnode
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py
index c0d75b5a..7d313605 100644
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -19,6 +19,7 @@ import sys
import io
import itertools
import warnings
+from typing import Optional, List
from astroid import bases
from astroid import context as contextmod
@@ -354,7 +355,9 @@ class Module(LocalsDictNodeNG):
'pure_python', 'future_imports')
_other_other_fields = ('locals', 'globals')
- def __init__(self, name, doc, file=None, path=None, package=None,
+ def __init__(self, name, doc, file=None,
+ path: Optional[List[str]]=None,
+ package=None,
parent=None, pure_python=True):
"""
:param name: The name of the module.
@@ -367,7 +370,7 @@ class Module(LocalsDictNodeNG):
:type file: str or None
:param path:
- :type path: str or None
+ :type path: Optional[List[str]]
:param package: Whether the node represents a package or a module.
:type package: bool or None