summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2010-09-22 15:05:42 +0200
committerEmile Anclin <emile.anclin@logilab.fr>2010-09-22 15:05:42 +0200
commitdbeaad5988d27f5fd56a278e70a8c7995c87ff7c (patch)
tree8833c2c86dfca6bfa91aebbe18817fe2e10ab677
parente2f48476e242dcee95a6de024c937720c39ed29b (diff)
downloadastroid-git-dbeaad5988d27f5fd56a278e70a8c7995c87ff7c.tar.gz
py2.3 compat : syntax, set; _nodes_compiler.py : fix visit_discard
--HG-- branch : stable
-rw-r--r--_nodes_compiler.py19
-rw-r--r--bases.py4
-rw-r--r--mixins.py3
-rw-r--r--node_classes.py8
-rw-r--r--nodes.py14
-rw-r--r--nodes_as_string.py6
-rw-r--r--rebuilder.py4
-rw-r--r--scoped_nodes.py12
-rw-r--r--utils.py2
9 files changed, 37 insertions, 35 deletions
diff --git a/_nodes_compiler.py b/_nodes_compiler.py
index e16d9eb6..2b59807a 100644
--- a/_nodes_compiler.py
+++ b/_nodes_compiler.py
@@ -37,7 +37,8 @@
__docformat__ = "restructuredtext en"
-from compiler.ast import Const, Node, Sliceobj
+from compiler.ast import Const, Node, Sliceobj, Function
+import sys
# nodes which are not part of astng
from compiler.ast import And as _And, Or as _Or,\
@@ -50,7 +51,7 @@ from compiler.ast import And as _And, Or as _Or,\
from logilab.astng import nodes as new
from logilab.astng.rebuilder import RebuildVisitor
-
+from logilab.common.compat import set
CONST_NAME_TRANSFORMS = {'None': None,
'True': True,
@@ -121,6 +122,8 @@ UnaryOp_OP_CLASSES = {_UnaryAdd: '+',
_Invert: '~'
}
+if sys.version_info < (2, 4):
+ Function.decorators = None
# compiler rebuilder ##########################################################
@@ -398,10 +401,11 @@ class TreeRebuilder(RebuildVisitor):
def visit_discard(self, node, parent):
"""visit a Discard node by returning a fresh instance of it"""
newnode = new.Discard()
- if node.lineno is None:
- # ignore dummy Discard introduced when a statement
- # is ended by a semi-colon: remove it at the end of rebuilding
- self._remove_nodes.append((newnode, parent))
+ if sys.version_info >= (2, 4) and node.lineno is None:
+ # ignore dummy Discard introduced when a statement
+ # is ended by a semi-colon: remove it at the end of rebuilding
+ # however, it does also happen in regular Discard nodes on 2.3
+ self._remove_nodes.append((newnode, parent))
self._set_infos(node, newnode, parent)
self.asscontext = "Dis"
newnode.value = self.visit(node.expr, newnode)
@@ -456,8 +460,7 @@ class TreeRebuilder(RebuildVisitor):
"""visit a Function node by returning a fresh instance of it"""
newnode = new.Function(node.name, node.doc)
self._set_infos(node, newnode, parent)
- if hasattr(node, 'decorators'):
- newnode.decorators = self.visit(node.decorators, newnode)
+ newnode.decorators = self.visit(node.decorators, newnode)
newnode.args = self.visit_arguments(node, newnode)
newnode.body = [self.visit(child, newnode) for child in node.code.nodes]
return newnode
diff --git a/bases.py b/bases.py
index ea3c9c6c..8422d676 100644
--- a/bases.py
+++ b/bases.py
@@ -51,8 +51,8 @@ except ImportError:
pass
from logilab.common.compat import set
-from logilab.astng._exceptions import (InferenceError, ASTNGError,
- NotFoundError, UnresolvableName)
+from logilab.astng._exceptions import InferenceError, ASTNGError, \
+ NotFoundError, UnresolvableName
class Proxy(BaseClass):
diff --git a/mixins.py b/mixins.py
index 7b9606b5..776c8874 100644
--- a/mixins.py
+++ b/mixins.py
@@ -33,8 +33,7 @@
"""
-from logilab.astng import (ASTNGBuildingException, InferenceError,
- NotFoundError)
+from logilab.astng import ASTNGBuildingException, InferenceError, NotFoundError
from logilab.astng.bases import BaseClass
# /!\ We cannot build a StmtNode(NodeNG) class since modifying "__bases__"
diff --git a/node_classes.py b/node_classes.py
index c5e4dcec..c9311759 100644
--- a/node_classes.py
+++ b/node_classes.py
@@ -23,10 +23,10 @@
from logilab.common.compat import chain, imap
from logilab.astng import NoDefault
-from logilab.astng.bases import (NodeNG, BaseClass, Instance, copy_context,
- _infer_stmts, YES)
-from logilab.astng.mixins import (StmtMixIn, BlockRangeMixIn, AssignTypeMixin,
- ParentAssignTypeMixin, FromImportMixIn)
+from logilab.astng.bases import NodeNG, BaseClass, Instance, copy_context, \
+ _infer_stmts, YES
+from logilab.astng.mixins import StmtMixIn, BlockRangeMixIn, AssignTypeMixin, \
+ ParentAssignTypeMixin, FromImportMixIn
def unpack_infer(stmt, context=None):
"""return an iterator on nodes inferred by the given statement if the
diff --git a/nodes.py b/nodes.py
index 7d5b4631..ce6bdcee 100644
--- a/nodes.py
+++ b/nodes.py
@@ -51,13 +51,13 @@ on From and Import :
__docformat__ = "restructuredtext en"
-from logilab.astng.node_classes import (Arguments, AssAttr, Assert,
- Assign, AssName, AugAssign, Backquote, BinOp, BoolOp, Break, CallFunc, Compare,
- Comprehension, Const, Continue, Decorators, DelAttr, DelName, Delete,
- Dict, Discard, Ellipsis, EmptyNode, ExceptHandler, Exec, ExtSlice, For,
- From, Getattr, Global, If, IfExp, Import, Index, Keyword,
- List, ListComp, Name, Pass, Print, Raise, Return, Slice, Subscript,
- TryExcept, TryFinally, Tuple, UnaryOp, While, With, Yield, const_factory )
+from logilab.astng.node_classes import Arguments, AssAttr, Assert, Assign, \
+ AssName, AugAssign, Backquote, BinOp, BoolOp, Break, CallFunc, Compare, \
+ Comprehension, Const, Continue, Decorators, DelAttr, DelName, Delete, \
+ Dict, Discard, Ellipsis, EmptyNode, ExceptHandler, Exec, ExtSlice, For, \
+ From, Getattr, Global, If, IfExp, Import, Index, Keyword, \
+ List, ListComp, Name, Pass, Print, Raise, Return, Slice, Subscript, \
+ TryExcept, TryFinally, Tuple, UnaryOp, While, With, Yield, const_factory
from logilab.astng.scoped_nodes import Module, GenExpr, Lambda, Function, Class
ALL_NODE_CLASSES = (
diff --git a/nodes_as_string.py b/nodes_as_string.py
index 6bb7d5fb..0a0f287f 100644
--- a/nodes_as_string.py
+++ b/nodes_as_string.py
@@ -63,7 +63,7 @@ class AsStringVisitor(ASTVisitor):
def _stmt_list(self, stmts):
"""return a list of nodes to string"""
- stmts = '\n'.join([nstr for nstr in (n.accept(self) for n in stmts) if nstr])
+ stmts = '\n'.join([nstr for nstr in [n.accept(self) for n in stmts] if nstr])
return INDENT + stmts.replace('\n', '\n'+INDENT)
@@ -167,7 +167,7 @@ class AsStringVisitor(ASTVisitor):
def visit_decorators(self, node):
"""return an astng.Decorators node as string"""
- return '@%s\n' % '\n@'.join(item.accept(self) for item in node.nodes)
+ return '@%s\n' % '\n@'.join([item.accept(self) for item in node.nodes])
def visit_dict(self, node):
"""return an astng.Dict node as string"""
@@ -210,7 +210,7 @@ class AsStringVisitor(ASTVisitor):
def visit_extslice(self, node):
"""return an astng.ExtSlice node as string"""
- return ','.join( dim.accept(self) for dim in node.dims )
+ return ','.join( [dim.accept(self) for dim in node.dims] )
def visit_for(self, node):
"""return an astng.For node as string"""
fors = 'for %s in %s:\n%s' % (node.target.accept(self),
diff --git a/rebuilder.py b/rebuilder.py
index d902875e..4bdbc6ca 100644
--- a/rebuilder.py
+++ b/rebuilder.py
@@ -214,11 +214,11 @@ class RebuildVisitor(object):
for name in imported.wildcard_import_names():
node.parent.set_local(name, node)
if delayed:
- node.parent.scope().locals[name].sort(cmp=cmp_nodes)
+ node.parent.scope().locals[name].sort(cmp_nodes)
else:
node.parent.set_local(asname or name, node)
if delayed:
- node.parent.scope().locals[asname or name].sort(cmp=cmp_nodes)
+ node.parent.scope().locals[asname or name].sort(cmp_nodes)
def visit_function(self, node, parent):
diff --git a/scoped_nodes.py b/scoped_nodes.py
index b096249e..9238983d 100644
--- a/scoped_nodes.py
+++ b/scoped_nodes.py
@@ -34,12 +34,12 @@ from logilab.common.decorators import cached
from logilab.astng import MANAGER, NotFoundError, NoDefault, \
ASTNGBuildingException, InferenceError
-from logilab.astng.node_classes import (Const, DelName, DelAttr,
- Dict, From, List, Name, Pass, Raise, Return, Tuple, Yield,
- are_exclusive, LookupMixIn, const_factory as cf, unpack_infer)
-from logilab.astng.bases import (NodeNG, BaseClass, InferenceContext, Instance,
- YES, Generator, UnboundMethod, BoundMethod, _infer_stmts, copy_context)
-from logilab.astng.mixins import (StmtMixIn, FilterStmtsMixin)
+from logilab.astng.node_classes import Const, DelName, DelAttr, \
+ Dict, From, List, Name, Pass, Raise, Return, Tuple, Yield, \
+ are_exclusive, LookupMixIn, const_factory as cf, unpack_infer
+from logilab.astng.bases import NodeNG, BaseClass, InferenceContext, Instance,\
+ YES, Generator, UnboundMethod, BoundMethod, _infer_stmts, copy_context
+from logilab.astng.mixins import StmtMixIn, FilterStmtsMixin
from logilab.astng.nodes_as_string import as_string
diff --git a/utils.py b/utils.py
index 524a2ccb..cf2a7c78 100644
--- a/utils.py
+++ b/utils.py
@@ -37,7 +37,7 @@ extract information from it
__docformat__ = "restructuredtext en"
from logilab.astng._exceptions import IgnoreChild, ASTNGBuildingException
-
+from logilab.common.compat import set
class ASTVisitor(object):
"""Abstract Base Class for Python AST Visitors.