summaryrefslogtreecommitdiff
path: root/astroid/nodes.py
diff options
context:
space:
mode:
authorCeridwen <ceridwenv@gmail.com>2015-07-10 11:48:53 -0400
committerCeridwen <ceridwenv@gmail.com>2015-07-10 11:48:53 -0400
commit251f1e41ff98a86b9e14b064b116ad646dbb562b (patch)
treec12a18e069efa02e99818214aa5c907e732aeabc /astroid/nodes.py
parent8abf328539e0e5f1dbafe70b773bfebd28afca77 (diff)
downloadastroid-git-251f1e41ff98a86b9e14b064b116ad646dbb562b.tar.gz
Refactor node classes to have constructors and change some names.
I corrected the spelling of 'infered' to 'infered' and changed some to make them more consistent with the built-in ast module and to read better in English. I created aliases with proxy objects to maintain backwards compatibility. I also refactored the node classes so that they have __init__ and postinit functions. The postinit function has to be called after the creation of a parent with the instances of its children because the node __init__ functions have to take a parent instance to maintain the doubly-linked structure of the AST. This involved moving considerable amounts of node-construction logic from rebuilder.py to node_classes.py and scoped_nodes.py.
Diffstat (limited to 'astroid/nodes.py')
-rw-r--r--astroid/nodes.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/astroid/nodes.py b/astroid/nodes.py
index 4325c7e2..82b2fb7a 100644
--- a/astroid/nodes.py
+++ b/astroid/nodes.py
@@ -38,6 +38,8 @@ on ImportFrom and Import :
__docformat__ = "restructuredtext en"
+import lazy_object_proxy
+
from astroid.node_classes import (
Arguments, AssignAttr, Assert, Assign,
AssignName, AugAssign, Repr, BinOp, BoolOp, Break, Call, Compare,
@@ -53,6 +55,7 @@ from astroid.scoped_nodes import (
ListComp, SetComp, FunctionDef, ClassDef,
)
+
ALL_NODE_CLASSES = (
Arguments, AssignAttr, Assert, Assign, AssignName, AugAssign,
Repr, BinOp, BoolOp, Break,
@@ -75,3 +78,20 @@ ALL_NODE_CLASSES = (
While, With,
Yield, YieldFrom
)
+
+
+# Backward-compatibility aliases
+def proxy_alias(alias_name, node_type):
+ proxy = type(alias_name, (lazy_object_proxy.Proxy,),
+ {'__class__': object.__dict__['__class__']})
+ return proxy(node_type)
+
+Backquote = proxy_alias('Backquote', Repr)
+Discard = proxy_alias('Discard', Expr)
+AssName = proxy_alias('AssName', AssignName)
+AssAttr = proxy_alias('AssAttr', AssignAttr)
+GetAttr = proxy_alias('GetAttr', Attribute)
+CallFunc = proxy_alias('CallFunc', Call)
+Class = proxy_alias('Class', ClassDef)
+Function = proxy_alias('Function', FunctionDef)
+GenExpr = proxy_alias('GenExpr', GeneratorExp)