fixes for python 3.3 ast nodes changes. Closes #120646

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset5b50ca6572a5
branchdefault
phasepublic
hiddenno
parent revision#01880cb261d7 fix Changelog
child revision#f86e7fd1161f backport proper subprocess.Popen implementation from pylint brain. See #46273
files modified by this revision
ChangeLog
rebuilder.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1361546940 -3600
# Fri Feb 22 16:29:00 2013 +0100
# Node ID 5b50ca6572a5ca0ad1a47f1ff6e727c45b97a0dd
# Parent 01880cb261d7684bdcc60b78215b60df761528ac
fixes for python 3.3 ast nodes changes. Closes #120646

diff --git a/ChangeLog b/ChangeLog
@@ -2,10 +2,11 @@
1  ================================
2 
3    --
4 
5      * #109562 [jython]: java modules have no __doc__, causing crash
6 +    * #120646 [py3]: fix for python3.3 _ast changes which may cause crash
7      * #109988 [py3]: test fixes
8 
9  2012-10-05  -- 0.24.1
10      * #106191: fix __future__ absolute import w/ From node
11      * #50395: fix function fromlineno when some decorator is splited on
diff --git a/rebuilder.py b/rebuilder.py
@@ -1,9 +1,7 @@
12 -# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
13 +# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
14  # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
15 -# copyright 2003-2010 Sylvain Thenault, all rights reserved.
16 -# contact mailto:thenault@gmail.com
17  #
18  # This file is part of logilab-astng.
19  #
20  # logilab-astng is free software: you can redistribute it and/or modify it
21  # under the terms of the GNU Lesser General Public License as published by the
@@ -786,17 +784,17 @@
22          newnode.orelse = [self.visit(child, newnode) for child in node.orelse]
23          newnode.set_line_info(newnode.last_child())
24          return newnode
25 
26      def visit_with(self, node, parent):
27 -        """visit a With node by returning a fresh instance of it"""
28          newnode = new.With()
29          _lineno_parent(node, newnode, parent)
30 -        newnode.expr = self.visit(node.context_expr, newnode)
31 +        _node = getattr(node, 'items', [node])[0] # python 3.3 XXX
32 +        newnode.expr = self.visit(_node.context_expr, newnode)
33          self.asscontext = "Ass"
34 -        if node.optional_vars is not None:
35 -            newnode.vars = self.visit(node.optional_vars, newnode)
36 +        if _node.optional_vars is not None:
37 +            newnode.vars = self.visit(_node.optional_vars, newnode)
38          self.asscontext = None
39          newnode.body = [self.visit(child, newnode) for child in node.body]
40          newnode.set_line_info(newnode.last_child())
41          return newnode
42 
@@ -855,10 +853,34 @@
43          _lineno_parent(node, newnode, parent)
44          newnode.value = self.visit(node.value, newnode)
45          newnode.set_line_info(newnode.last_child())
46          return newnode
47 
48 +    def visit_try(self, node, parent):
49 +        # python 3.3 introduce a new Try node replacing TryFinally/TryExcept nodes
50 +        if node.finalbody:
51 +            newnode = new.TryFinally()
52 +            _lineno_parent(node, newnode, parent)
53 +            newnode.finalbody = [self.visit(n, newnode) for n in node.finalbody]
54 +            if node.handlers:
55 +                excnode = new.TryExcept()
56 +                _lineno_parent(node, excnode, parent)
57 +                excnode.body = [self.visit(child, newnode) for child in node.body]
58 +                excnode.handlers = [self.visit(child, newnode) for child in node.handlers]
59 +                excnode.orelse = [self.visit(child, newnode) for child in node.orelse]
60 +                newnode.body = [excnode]
61 +            else:
62 +                newnode.body = [self.visit(child, newnode) for child in node.body]
63 +        elif node.handlers:
64 +            newnode = new.TryExcept()
65 +            _lineno_parent(node, newnode, parent)
66 +            newnode.body = [self.visit(child, newnode) for child in node.body]
67 +            newnode.handlers = [self.visit(child, newnode) for child in node.handlers]
68 +            newnode.orelse = [self.visit(child, newnode) for child in node.orelse]
69 +        newnode.set_line_info(newnode.last_child())
70 +        return newnode
71 +
72 
73  if sys.version_info >= (3, 0):
74      TreeRebuilder = TreeRebuilder3k
75 
76