summaryrefslogtreecommitdiff
path: root/astroid/builder.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-04-25 17:23:11 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2016-04-25 17:23:11 +0300
commit08c53a9416870b320eae50490dd5ceef0321c580 (patch)
tree181f685b57e014543afca4c37930883e3887c389 /astroid/builder.py
parentefb72b8f11528cff73739023b6e2273d5c5b022d (diff)
downloadastroid-git-08c53a9416870b320eae50490dd5ceef0321c580.tar.gz
Don't take in consideration invalid assignments, especially when __slots__ declaration forbids them.
Close issue #332
Diffstat (limited to 'astroid/builder.py')
-rw-r--r--astroid/builder.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/astroid/builder.py b/astroid/builder.py
index 3738e94f..48001e5b 100644
--- a/astroid/builder.py
+++ b/astroid/builder.py
@@ -78,6 +78,17 @@ else:
MANAGER = manager.AstroidManager()
+def _can_assign_attr(node, attrname):
+ try:
+ slots = node.slots()
+ except NotImplementedError:
+ pass
+ else:
+ if slots and attrname not in set(slot.value for slot in slots):
+ return False
+ return True
+
+
class AstroidBuilder(raw_building.InspectBuilder):
"""Class for building an astroid tree from source code or from a live module.
@@ -226,6 +237,8 @@ class AstroidBuilder(raw_building.InspectBuilder):
if inferred.__class__ is bases.Instance:
inferred = inferred._proxied
iattrs = inferred.instance_attrs
+ if not _can_assign_attr(inferred, node.attrname):
+ continue
elif isinstance(inferred, bases.Instance):
# Const, Tuple, ... we may be wrong, may be not, but
# anyway we don't want to pollute builtin's namespace