summaryrefslogtreecommitdiff
path: root/astroid/tree/scoped_nodes.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-02-18 21:55:32 +0000
committerClaudiu Popa <pcmanticore@gmail.com>2016-02-18 21:55:32 +0000
commit5f9f8df7aa92981fbb41ea01535c5928ec8c2e08 (patch)
tree680afbb5b4c5aa612b34c520bdfdf228f46ebfa1 /astroid/tree/scoped_nodes.py
parentfd1f8c78be2b295405111f5db05e47457ee618a5 (diff)
downloadastroid-git-5f9f8df7aa92981fbb41ea01535c5928ec8c2e08.tar.gz
imported_names() got replaced by public_names()
Our understanding of wildcard imports through __all__ was half baked to say at least, since we couldn't account for modifications of the list, which results in tons of false positives. Instead, we replaced it with public_names(), a method which returns all the names that are publicly available in a module, that is that don't start with an underscore, even though this means that there is a possibility for other names to be leaked out even though they are not present in the __all__ variable. Close #322
Diffstat (limited to 'astroid/tree/scoped_nodes.py')
-rw-r--r--astroid/tree/scoped_nodes.py54
1 files changed, 3 insertions, 51 deletions
diff --git a/astroid/tree/scoped_nodes.py b/astroid/tree/scoped_nodes.py
index 6744ec82..36483ae7 100644
--- a/astroid/tree/scoped_nodes.py
+++ b/astroid/tree/scoped_nodes.py
@@ -380,57 +380,9 @@ class Module(QualifiedNameMixin, lookup.LocalsDictNode):
return '%s.%s' % (package_name, modname)
return modname
- def wildcard_import_names(self):
- """return the list of imported names when this module is 'wildcard
- imported'
-
- It doesn't include the '__builtins__' name which is added by the
- current CPython implementation of wildcard imports.
- """
- # We separate the different steps of lookup in try/excepts
- # to avoid catching too many Exceptions
- default = [name for name in self.keys() if not name.startswith('_')]
- if '__all__' in self:
- # This is a workaround for the case where a module defines
- # __all__ and then dynamically alters it, requiring a
- # custom hack to define a static __all__ for the module.
- # The static __all__ ends up at the end of the locals list
- # for __all__, not the beginning.
- all = self.locals['__all__'][-1]
- else:
- return default
-
- try:
- explicit = next(all.assigned_stmts())
- except exceptions.InferenceError:
- return default
- except AttributeError:
- # not an assignment node
- # XXX infer?
- return default
-
- # Try our best to detect the exported name.
- inferred = []
- try:
- explicit = next(explicit.infer())
- except exceptions.InferenceError:
- return default
- if not isinstance(explicit, (node_classes.Tuple, node_classes.List)):
- return default
-
- str_const = lambda node: (isinstance(node, node_classes.Const) and
- isinstance(node.value, six.string_types))
- for node in explicit.elts:
- if str_const(node):
- inferred.append(node.value)
- else:
- try:
- inferred_node = next(node.infer())
- except exceptions.InferenceError:
- continue
- if str_const(inferred_node):
- inferred.append(inferred_node.value)
- return inferred
+ def public_names(self):
+ """Get the list of the names which are publicly available in this module."""
+ return [name for name in self.keys() if not name.startswith('_')]
def bool_value(self):
return True