summaryrefslogtreecommitdiff
path: root/scoped_nodes.py
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2014-10-28 16:27:18 +0200
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2014-10-28 16:27:18 +0200
commite33bd26865b4bae43e979fed16a4a96259be66df (patch)
tree95d9165d76d2bd2e61f9e0aef13e1fe9f34b63c3 /scoped_nodes.py
parent6f3e3dac14b10a86793aed9003c3110dd1a3ce9f (diff)
downloadastroid-git-e33bd26865b4bae43e979fed16a4a96259be66df.tar.gz
Module.wildcard_import_names tries to infer non-const entries from __all__.
Diffstat (limited to 'scoped_nodes.py')
-rw-r--r--scoped_nodes.py32
1 files changed, 23 insertions, 9 deletions
diff --git a/scoped_nodes.py b/scoped_nodes.py
index b234050a..8bdebfc8 100644
--- a/scoped_nodes.py
+++ b/scoped_nodes.py
@@ -413,24 +413,38 @@ class Module(LocalsDictNodeNG):
#
# We separate the different steps of lookup in try/excepts
# to avoid catching too many Exceptions
- # However, we can not analyse dynamically constructed __all__
+ default = [name for name in self.keys() if not name.startswith('_')]
try:
all = self['__all__']
except KeyError:
- return [name for name in self.keys() if not name.startswith('_')]
+ return default
try:
explicit = next(all.assigned_stmts())
except InferenceError:
- return [name for name in self.keys() if not name.startswith('_')]
+ return default
except AttributeError:
# not an assignment node
# XXX infer?
- return [name for name in self.keys() if not name.startswith('_')]
- try:
- # should be a Tuple/List of constant string / 1 string not allowed
- return [const.value for const in explicit.elts]
- except AttributeError:
- return [name for name in self.keys() if not name.startswith('_')]
+ return default
+
+ # Try our best to detect the exported name.
+ infered = []
+ if not isinstance(explicit, Tuple):
+ return default
+ str_const = lambda node: (isinstance(node, Const) and
+ isinstance(node.value, six.string_types))
+ for node in explicit.elts:
+ if str_const(node):
+ infered.append(node.value)
+ else:
+ try:
+ infered_node = next(node.infer())
+ except InferenceError:
+ continue
+ if str_const(infered_node):
+ infered.append(infered_node.value)
+ return infered
+
class ComprehensionScope(LocalsDictNodeNG):