diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | astroid/interpreter/objectmodel.py | 11 | ||||
-rw-r--r-- | astroid/rebuilder.py | 3 | ||||
-rw-r--r-- | astroid/scoped_nodes.py | 7 |
4 files changed, 25 insertions, 6 deletions
@@ -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 |