Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: third_party/logilab/astroid/utils.py

Issue 753543006: pylint: upgrade to 1.4.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/logilab/astroid/scoped_nodes.py ('k') | third_party/logilab/common/README.chromium » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. 1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
3 # 3 #
4 # This file is part of astroid. 4 # This file is part of astroid.
5 # 5 #
6 # astroid is free software: you can redistribute it and/or modify it 6 # astroid is free software: you can redistribute it and/or modify it
7 # under the terms of the GNU Lesser General Public License as published by the 7 # under the terms of the GNU Lesser General Public License as published by the
8 # Free Software Foundation, either version 2.1 of the License, or (at your 8 # Free Software Foundation, either version 2.1 of the License, or (at your
9 # option) any later version. 9 # option) any later version.
10 # 10 #
11 # astroid is distributed in the hope that it will be useful, but 11 # astroid is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 # for more details. 14 # for more details.
15 # 15 #
16 # You should have received a copy of the GNU Lesser General Public License along 16 # You should have received a copy of the GNU Lesser General Public License along
17 # with astroid. If not, see <http://www.gnu.org/licenses/>. 17 # with astroid. If not, see <http://www.gnu.org/licenses/>.
18 """this module contains some utilities to navigate in the tree or to 18 """this module contains some utilities to navigate in the tree or to
19 extract information from it 19 extract information from it
20 """ 20 """
21 from __future__ import print_function
21 22
22 __docformat__ = "restructuredtext en" 23 __docformat__ = "restructuredtext en"
23 24
24 from astroid.exceptions import AstroidBuildingException 25 from astroid.exceptions import AstroidBuildingException
25 from astroid.builder import parse 26 from astroid.builder import parse
26 27
27 28
28 class ASTWalker(object): 29 class ASTWalker(object):
29 """a walker visiting a tree in preorder, calling on the handler: 30 """a walker visiting a tree in preorder, calling on the handler:
30 31
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 self.visit(local_node) 103 self.visit(local_node)
103 if methods[1] is not None: 104 if methods[1] is not None:
104 return methods[1](node) 105 return methods[1](node)
105 106
106 107
107 def _check_children(node): 108 def _check_children(node):
108 """a helper function to check children - parent relations""" 109 """a helper function to check children - parent relations"""
109 for child in node.get_children(): 110 for child in node.get_children():
110 ok = False 111 ok = False
111 if child is None: 112 if child is None:
112 print "Hm, child of %s is None" % node 113 print("Hm, child of %s is None" % node)
113 continue 114 continue
114 if not hasattr(child, 'parent'): 115 if not hasattr(child, 'parent'):
115 print " ERROR: %s has child %s %x with no parent" % ( 116 print(" ERROR: %s has child %s %x with no parent" % (
116 node, child, id(child)) 117 node, child, id(child)))
117 elif not child.parent: 118 elif not child.parent:
118 print " ERROR: %s has child %s %x with parent %r" % ( 119 print(" ERROR: %s has child %s %x with parent %r" % (
119 node, child, id(child), child.parent) 120 node, child, id(child), child.parent))
120 elif child.parent is not node: 121 elif child.parent is not node:
121 print " ERROR: %s %x has child %s %x with wrong parent %s" % ( 122 print(" ERROR: %s %x has child %s %x with wrong parent %s" % (
122 node, id(node), child, id(child), child.parent) 123 node, id(node), child, id(child), child.parent))
123 else: 124 else:
124 ok = True 125 ok = True
125 if not ok: 126 if not ok:
126 print "lines;", node.lineno, child.lineno 127 print("lines;", node.lineno, child.lineno)
127 print "of module", node.root(), node.root().name 128 print("of module", node.root(), node.root().name)
128 raise AstroidBuildingException 129 raise AstroidBuildingException
129 _check_children(child) 130 _check_children(child)
130 131
131 132
132 class TreeTester(object): 133 class TreeTester(object):
133 '''A helper class to see _ast tree and compare with astroid tree 134 '''A helper class to see _ast tree and compare with astroid tree
134 135
135 indent: string for tree indent representation 136 indent: string for tree indent representation
136 lineno: bool to tell if we should print the line numbers 137 lineno: bool to tell if we should print the line numbers
137 138
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 return tree 230 return tree
230 231
231 def astroid_tree_repr(self, ids=False): 232 def astroid_tree_repr(self, ids=False):
232 """build the astroid tree and return a nice tree representation""" 233 """build the astroid tree and return a nice tree representation"""
233 mod = self.build_astroid_tree() 234 mod = self.build_astroid_tree()
234 return mod.repr_tree(ids) 235 return mod.repr_tree(ids)
235 236
236 237
237 __all__ = ('LocalsVisitor', 'ASTWalker',) 238 __all__ = ('LocalsVisitor', 'ASTWalker',)
238 239
OLDNEW
« no previous file with comments | « third_party/logilab/astroid/scoped_nodes.py ('k') | third_party/logilab/common/README.chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698