summaryrefslogtreecommitdiff
path: root/rebuilder.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2013-08-14 14:38:42 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2013-08-14 14:38:42 +0300
commitcc301b2e96da6916a482e583183e32b8f5894c77 (patch)
treeb480439e7b06dc5345b77278498cc61e5b22f65c /rebuilder.py
parent2579966614a246ce3bb1bad67238f6a0b36f0ff6 (diff)
downloadastroid-git-cc301b2e96da6916a482e583183e32b8f5894c77.tar.gz
Proper metaclass discovery when encountering __metaclass__.
--HG-- branch : metaclass
Diffstat (limited to 'rebuilder.py')
-rw-r--r--rebuilder.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/rebuilder.py b/rebuilder.py
index 862de858..c9d2e218 100644
--- a/rebuilder.py
+++ b/rebuilder.py
@@ -21,7 +21,7 @@ order to get a single Astroid representation
import sys
from warnings import warn
-from _ast import (Expr as Discard, Str,
+from _ast import (Expr as Discard, Str, Name, Attribute,
# binary operators
Add, Div, FloorDiv, Mod, Mult, Pow, Sub, BitAnd, BitOr, BitXor,
LShift, RShift,
@@ -114,7 +114,11 @@ def _set_infos(oldnode, newnode, parent):
newnode.col_offset = oldnode.col_offset
newnode.set_line_info(newnode.last_child()) # set_line_info accepts None
-
+def _infer_metaclass(node):
+ if isinstance(node, Name):
+ return node.id
+ elif isinstance(node, Attribute):
+ return node.attr
class TreeRebuilder(object):
@@ -245,7 +249,7 @@ class TreeRebuilder(object):
continue
elif getattr(newnode.targets[0], 'name', None) == '__metaclass__':
# XXX check more...
- self._metaclass[-1] = 'type'
+ self._metaclass[-1] = _infer_metaclass(node.value)
newnode.set_line_info(newnode.last_child())
return newnode
@@ -331,7 +335,7 @@ class TreeRebuilder(object):
if not newnode.bases:
# no base classes, detect new / style old style according to
# current scope
- newnode._newstyle = metaclass == 'type'
+ newnode._newstyle = metaclass in ('type', 'ABCMeta')
newnode.parent.frame().set_local(newnode.name, newnode)
return newnode