summaryrefslogtreecommitdiff
path: root/astroid/util.py
diff options
context:
space:
mode:
authorCeridwen <ceridwenv@gmail.com>2015-10-08 10:26:11 -0400
committerCeridwen <ceridwenv@gmail.com>2015-10-08 10:26:11 -0400
commit64d9868aa0aa5b24a590fa8c057572f1812ef632 (patch)
tree35b5e6595cefbaa9ef645723b7acb9d99fddc633 /astroid/util.py
parent969e05b12c68df090c784a0e89fabfe69f6efe87 (diff)
downloadastroid-git-64d9868aa0aa5b24a590fa8c057572f1812ef632.tar.gz
Example of unclear ImportError
Diffstat (limited to 'astroid/util.py')
-rw-r--r--astroid/util.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/astroid/util.py b/astroid/util.py
index 96ba5fbf..8e96f935 100644
--- a/astroid/util.py
+++ b/astroid/util.py
@@ -23,6 +23,8 @@ import sys
import six
+from astroid import exceptions
+
def reraise(exception):
'''Reraises an exception with the traceback from the current exception
@@ -45,3 +47,27 @@ class YES(object):
def __call__(self, *args, **kwargs):
return self
+
+
+def get_external_assignments(root, subject, attributes):
+ stack = [root]
+ while stack:
+ node = stack.pop()
+ stack.extend(node.get_children())
+ if isinstance(node, node_classes.AssignAttr):
+ frame = node.frame()
+ try:
+ for inferred in (n for n in node.expr.infer() if n is subject):
+ values = attributes[node.attrname]
+ if node in values:
+ continue
+ else:
+ if (values and frame.is_function and
+ frame.name == '__init__' and not
+ values[0].frame().name == '__init__'):
+ values.insert(0, node)
+ else:
+ values.append(node)
+ except exceptions.InferenceError:
+ pass
+ return attributes