summaryrefslogtreecommitdiff
path: root/_nodes.py
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2009-09-02 19:38:08 +0200
committerEmile Anclin <emile.anclin@logilab.fr>2009-09-02 19:38:08 +0200
commit6404277c5471119ee0444a67144f57d698b24411 (patch)
tree4272d7118360b5ee8adbb64b1118eb3f6bb9eac8 /_nodes.py
parent586de3f84f1d0d3812399c013806c41c508af0ff (diff)
downloadastroid-git-6404277c5471119ee0444a67144f57d698b24411.tar.gz
[R] add an _nodes.py for avoiding circular imports.py
Diffstat (limited to '_nodes.py')
-rw-r--r--_nodes.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/_nodes.py b/_nodes.py
new file mode 100644
index 00000000..5958378d
--- /dev/null
+++ b/_nodes.py
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+"""
+Module containing the node classes; it is only used for avoiding circular imports
+"""
+
+from __future__ import generators
+
+__docformat__ = "restructuredtext en"
+
+from itertools import imap
+
+try:
+ from logilab.astng._nodes_ast import *
+ from logilab.astng._nodes_ast import _const_factory
+ AST_MODE = '_ast'
+except ImportError:
+ from logilab.astng._nodes_compiler import *
+ from logilab.astng._nodes_compiler import _const_factory
+ AST_MODE = 'compiler'
+
+
+INFER_NEED_NAME_STMTS = (From, Import, Global, TryExcept)
+LOOP_SCOPES = (Comprehension, For,)
+
+
+STMT_NODES = (
+ Assert, Assign, AugAssign, Break, Class, Continue, Delete, Discard,
+ ExceptHandler, Exec, For, From, Function, Global, If, Import, Pass, Print,
+ Raise, Return, TryExcept, TryFinally, While, With, Yield
+ )
+
+ALL_NODES = STMT_NODES + (
+ Arguments, AssAttr, AssName, BinOp, BoolOp, Backquote, CallFunc, Compare,
+ Comprehension, Const, Decorators, DelAttr, DelName, Dict, Ellipsis,
+ EmptyNode, ExtSlice, Getattr, GenExpr, IfExp, Index, Keyword, Lambda,
+ List, ListComp, Module, Name, Slice, Subscript, UnaryOp, Tuple
+ )
+
+# constants ... ##############################################################
+
+CONST_CLS = {
+ list: List,
+ tuple: Tuple,
+ dict: Dict,
+ }
+
+def const_factory(value):
+ """return an astng node for a python value"""
+ try:
+ # if value is of class list, tuple, dict use specific class, not Const
+ cls = CONST_CLS[value.__class__]
+ node = cls()
+ if isinstance(node, Dict):
+ node.items = ()
+ else:
+ node.elts = ()
+ except KeyError:
+ try:
+ node = Const(value)
+ except KeyError:
+ node = _const_factory(value)
+ return node
+