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

Unified Diff: third_party/logilab/astng/node_classes.py

Issue 719313003: Revert "pylint: upgrade to 1.3.1" (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/logilab/astng/mixins.py ('k') | third_party/logilab/astng/nodes.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/logilab/astng/node_classes.py
diff --git a/third_party/logilab/astroid/node_classes.py b/third_party/logilab/astng/node_classes.py
similarity index 77%
rename from third_party/logilab/astroid/node_classes.py
rename to third_party/logilab/astng/node_classes.py
index 6d59745812d96da764be4a2b18a45c795686d4ab..607ad9074f14183ab0072e8c860d04a38ddb8e2d 100644
--- a/third_party/logilab/astroid/node_classes.py
+++ b/third_party/logilab/astng/node_classes.py
@@ -1,32 +1,33 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+# copyright 2003-2010 Sylvain Thenault, all rights reserved.
+# contact mailto:thenault@gmail.com
#
-# This file is part of astroid.
+# This file is part of logilab-astng.
#
-# astroid is free software: you can redistribute it and/or modify it
+# logilab-astng is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 2.1 of the License, or (at your
# option) any later version.
#
-# astroid is distributed in the hope that it will be useful, but
+# logilab-astng 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 Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
-# with astroid. If not, see <http://www.gnu.org/licenses/>.
+# with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
"""Module for some node classes. More nodes in scoped_nodes.py
"""
import sys
-from astroid.exceptions import NoDefault
-from astroid.bases import (NodeNG, Statement, Instance, InferenceContext,
- _infer_stmts, YES, BUILTINS)
-from astroid.mixins import (BlockRangeMixIn, AssignTypeMixin,
- ParentAssignTypeMixin, FromImportMixIn)
-
-PY3K = sys.version_info >= (3, 0)
+from logilab.astng import BUILTINS_MODULE
+from logilab.astng.exceptions import NoDefault
+from logilab.astng.bases import (NodeNG, Statement, Instance, InferenceContext,
+ _infer_stmts, YES)
+from logilab.astng.mixins import BlockRangeMixIn, AssignTypeMixin, \
+ ParentAssignTypeMixin, FromImportMixIn
def unpack_infer(stmt, context=None):
@@ -38,18 +39,13 @@ def unpack_infer(stmt, context=None):
for infered_elt in unpack_infer(elt, context):
yield infered_elt
return
- # if infered is a final node, return it and stop
infered = stmt.infer(context).next()
- if infered is stmt:
+ if infered is stmt or infered is YES:
yield infered
return
- # else, infer recursivly, except YES object that should be returned as is
for infered in stmt.infer(context):
- if infered is YES:
- yield infered
- else:
- for inf_inf in unpack_infer(infered, context):
- yield inf_inf
+ for inf_inf in unpack_infer(infered, context):
+ yield inf_inf
def are_exclusive(stmt1, stmt2, exceptions=None):
@@ -84,16 +80,16 @@ def are_exclusive(stmt1, stmt2, exceptions=None):
# nodes are in exclusive branches
if isinstance(node, If) and exceptions is None:
if (node.locate_child(previous)[1]
- is not node.locate_child(children[node])[1]):
+ is not node.locate_child(children[node])[1]):
return True
elif isinstance(node, TryExcept):
c2attr, c2node = node.locate_child(previous)
c1attr, c1node = node.locate_child(children[node])
if c1node is not c2node:
if ((c2attr == 'body' and c1attr == 'handlers' and children[node].catch(exceptions)) or
- (c2attr == 'handlers' and c1attr == 'body' and previous.catch(exceptions)) or
- (c2attr == 'handlers' and c1attr == 'orelse') or
- (c2attr == 'orelse' and c1attr == 'handlers')):
+ (c2attr == 'handlers' and c1attr == 'body' and previous.catch(exceptions)) or
+ (c2attr == 'handlers' and c1attr == 'orelse') or
+ (c2attr == 'orelse' and c1attr == 'handlers')):
return True
elif c2attr == 'handlers' and c1attr == 'handlers':
return previous is not children[node]
@@ -110,13 +106,13 @@ class LookupMixIn(object):
def lookup(self, name):
"""lookup a variable name
- return the scope node and the list of assignments associated to the
- given name according to the scope where it has been found (locals,
- globals or builtin)
+ return the scope node and the list of assignments associated to the given
+ name according to the scope where it has been found (locals, globals or
+ builtin)
- The lookup is starting from self's scope. If self is not a frame itself
- and the name is found in the inner frame locals, statements will be
- filtered to remove ignorable statements according to self's location
+ The lookup is starting from self's scope. If self is not a frame itself and
+ the name is found in the inner frame locals, statements will be filtered
+ to remove ignorable statements according to self's location
"""
return self.scope().scope_lookup(self, name)
@@ -255,30 +251,9 @@ class Name(LookupMixIn, NodeNG):
class Arguments(NodeNG, AssignTypeMixin):
"""class representing an Arguments node"""
- if PY3K:
- # Python 3.4+ uses a different approach regarding annotations,
- # each argument is a new class, _ast.arg, which exposes an
- # 'annotation' attribute. In astroid though, arguments are exposed
- # as is in the Arguments node and the only way to expose annotations
- # is by using something similar with Python 3.3:
- # - we expose 'varargannotation' and 'kwargannotation' of annotations
- # of varargs and kwargs.
- # - we expose 'annotation', a list with annotations for
- # for each normal argument. If an argument doesn't have an
- # annotation, its value will be None.
-
- _astroid_fields = ('args', 'defaults', 'kwonlyargs',
- 'kw_defaults', 'annotations',
- 'varargannotation', 'kwargannotation')
- annotations = None
- varargannotation = None
- kwargannotation = None
- else:
- _astroid_fields = ('args', 'defaults', 'kwonlyargs', 'kw_defaults')
+ _astng_fields = ('args', 'defaults')
args = None
defaults = None
- kwonlyargs = None
- kw_defaults = None
def __init__(self, vararg=None, kwarg=None):
self.vararg = vararg
@@ -291,17 +266,11 @@ class Arguments(NodeNG, AssignTypeMixin):
def format_args(self):
"""return arguments formatted as string"""
- result = []
- if self.args:
- result.append(_format_args(self.args, self.defaults))
+ result = [_format_args(self.args, self.defaults)]
if self.vararg:
result.append('*%s' % self.vararg)
if self.kwarg:
result.append('**%s' % self.kwarg)
- if self.kwonlyargs:
- if not self.vararg:
- result.append('*')
- result.append(_format_args(self.kwonlyargs, self.kw_defaults))
return ', '.join(result)
def default_value(self, argname):
@@ -314,9 +283,6 @@ class Arguments(NodeNG, AssignTypeMixin):
idx = i - (len(self.args) - len(self.defaults))
if idx >= 0:
return self.defaults[idx]
- i = _find_arg(argname, self.kwonlyargs)[0]
- if i is not None and self.kw_defaults[i] is not None:
- return self.kw_defaults[i]
raise NoDefault()
def is_argument(self, name):
@@ -333,12 +299,6 @@ class Arguments(NodeNG, AssignTypeMixin):
return _find_arg(argname, self.args, rec)
return None, None
- def get_children(self):
- """override get_children to skip over None elements in kw_defaults"""
- for child in super(Arguments, self).get_children():
- if child is not None:
- yield child
-
def _find_arg(argname, args, rec=False):
for i, arg in enumerate(args):
@@ -364,48 +324,47 @@ def _format_args(args, defaults=None):
else:
values.append(arg.name)
if defaults is not None and i >= default_offset:
- if defaults[i-default_offset] is not None:
- values[-1] += '=' + defaults[i-default_offset].as_string()
+ values[-1] += '=' + defaults[i-default_offset].as_string()
return ', '.join(values)
class AssAttr(NodeNG, ParentAssignTypeMixin):
"""class representing an AssAttr node"""
- _astroid_fields = ('expr',)
+ _astng_fields = ('expr',)
expr = None
class Assert(Statement):
"""class representing an Assert node"""
- _astroid_fields = ('test', 'fail',)
+ _astng_fields = ('test', 'fail',)
test = None
fail = None
class Assign(Statement, AssignTypeMixin):
"""class representing an Assign node"""
- _astroid_fields = ('targets', 'value',)
+ _astng_fields = ('targets', 'value',)
targets = None
value = None
class AugAssign(Statement, AssignTypeMixin):
"""class representing an AugAssign node"""
- _astroid_fields = ('target', 'value',)
+ _astng_fields = ('target', 'value',)
target = None
value = None
class Backquote(NodeNG):
"""class representing a Backquote node"""
- _astroid_fields = ('value',)
+ _astng_fields = ('value',)
value = None
class BinOp(NodeNG):
"""class representing a BinOp node"""
- _astroid_fields = ('left', 'right',)
+ _astng_fields = ('left', 'right',)
left = None
right = None
class BoolOp(NodeNG):
"""class representing a BoolOp node"""
- _astroid_fields = ('values',)
+ _astng_fields = ('values',)
values = None
class Break(Statement):
@@ -414,7 +373,7 @@ class Break(Statement):
class CallFunc(NodeNG):
"""class representing a CallFunc node"""
- _astroid_fields = ('func', 'args', 'starargs', 'kwargs')
+ _astng_fields = ('func', 'args', 'starargs', 'kwargs')
func = None
args = None
starargs = None
@@ -426,7 +385,7 @@ class CallFunc(NodeNG):
class Compare(NodeNG):
"""class representing a Compare node"""
- _astroid_fields = ('left', 'ops',)
+ _astng_fields = ('left', 'ops',)
left = None
ops = None
@@ -444,7 +403,7 @@ class Compare(NodeNG):
class Comprehension(NodeNG):
"""class representing a Comprehension node"""
- _astroid_fields = ('target', 'iter', 'ifs')
+ _astng_fields = ('target', 'iter' ,'ifs')
target = None
iter = None
ifs = None
@@ -497,7 +456,7 @@ class Continue(Statement):
class Decorators(NodeNG):
"""class representing a Decorators node"""
- _astroid_fields = ('nodes',)
+ _astng_fields = ('nodes',)
nodes = None
def __init__(self, nodes=None):
@@ -509,29 +468,29 @@ class Decorators(NodeNG):
class DelAttr(NodeNG, ParentAssignTypeMixin):
"""class representing a DelAttr node"""
- _astroid_fields = ('expr',)
+ _astng_fields = ('expr',)
expr = None
class Delete(Statement, AssignTypeMixin):
"""class representing a Delete node"""
- _astroid_fields = ('targets',)
+ _astng_fields = ('targets',)
targets = None
class Dict(NodeNG, Instance):
"""class representing a Dict node"""
- _astroid_fields = ('items',)
+ _astng_fields = ('items',)
def __init__(self, items=None):
if items is None:
self.items = []
else:
self.items = [(const_factory(k), const_factory(v))
- for k, v in items.iteritems()]
+ for k,v in items.iteritems()]
def pytype(self):
- return '%s.dict' % BUILTINS
+ return '%s.dict' % BUILTINS_MODULE
def get_children(self):
"""get children of a Dict node"""
@@ -549,22 +508,19 @@ class Dict(NodeNG, Instance):
def itered(self):
return self.items[::2]
- def getitem(self, lookup_key, context=None):
- for key, value in self.items:
- for inferedkey in key.infer(context):
+ def getitem(self, key, context=None):
+ for i in xrange(0, len(self.items), 2):
+ for inferedkey in self.items[i].infer(context):
if inferedkey is YES:
continue
- if isinstance(inferedkey, Const) \
- and inferedkey.value == lookup_key:
- return value
- # This should raise KeyError, but all call sites only catch
- # IndexError. Let's leave it like that for now.
- raise IndexError(lookup_key)
+ if isinstance(inferedkey, Const) and inferedkey.value == key:
+ return self.items[i+1]
+ raise IndexError(key)
class Discard(Statement):
"""class representing a Discard node"""
- _astroid_fields = ('value',)
+ _astng_fields = ('value',)
value = None
@@ -578,7 +534,7 @@ class EmptyNode(NodeNG):
class ExceptHandler(Statement, AssignTypeMixin):
"""class representing an ExceptHandler node"""
- _astroid_fields = ('type', 'name', 'body',)
+ _astng_fields = ('type', 'name', 'body',)
type = None
name = None
body = None
@@ -606,7 +562,7 @@ class ExceptHandler(Statement, AssignTypeMixin):
class Exec(Statement):
"""class representing an Exec node"""
- _astroid_fields = ('expr', 'globals', 'locals',)
+ _astng_fields = ('expr', 'globals', 'locals',)
expr = None
globals = None
locals = None
@@ -614,12 +570,12 @@ class Exec(Statement):
class ExtSlice(NodeNG):
"""class representing an ExtSlice node"""
- _astroid_fields = ('dims',)
+ _astng_fields = ('dims',)
dims = None
class For(BlockRangeMixIn, AssignTypeMixin, Statement):
"""class representing a For node"""
- _astroid_fields = ('target', 'iter', 'body', 'orelse',)
+ _astng_fields = ('target', 'iter', 'body', 'orelse',)
target = None
iter = None
body = None
@@ -633,14 +589,14 @@ class For(BlockRangeMixIn, AssignTypeMixin, Statement):
class From(FromImportMixIn, Statement):
"""class representing a From node"""
- def __init__(self, fromname, names, level=0):
+ def __init__(self, fromname, names, level=0):
self.modname = fromname
self.names = names
self.level = level
class Getattr(NodeNG):
"""class representing a Getattr node"""
- _astroid_fields = ('expr',)
+ _astng_fields = ('expr',)
expr = None
@@ -656,7 +612,7 @@ class Global(Statement):
class If(BlockRangeMixIn, Statement):
"""class representing an If node"""
- _astroid_fields = ('test', 'body', 'orelse')
+ _astng_fields = ('test', 'body', 'orelse')
test = None
body = None
orelse = None
@@ -676,7 +632,7 @@ class If(BlockRangeMixIn, Statement):
class IfExp(NodeNG):
"""class representing an IfExp node"""
- _astroid_fields = ('test', 'body', 'orelse')
+ _astng_fields = ('test', 'body', 'orelse')
test = None
body = None
orelse = None
@@ -688,19 +644,19 @@ class Import(FromImportMixIn, Statement):
class Index(NodeNG):
"""class representing an Index node"""
- _astroid_fields = ('value',)
+ _astng_fields = ('value',)
value = None
class Keyword(NodeNG):
"""class representing a Keyword node"""
- _astroid_fields = ('value',)
+ _astng_fields = ('value',)
value = None
class List(NodeNG, Instance, ParentAssignTypeMixin):
"""class representing a List node"""
- _astroid_fields = ('elts',)
+ _astng_fields = ('elts',)
def __init__(self, elts=None):
if elts is None:
@@ -709,7 +665,7 @@ class List(NodeNG, Instance, ParentAssignTypeMixin):
self.elts = [const_factory(e) for e in elts]
def pytype(self):
- return '%s.list' % BUILTINS
+ return '%s.list' % BUILTINS_MODULE
def getitem(self, index, context=None):
return self.elts[index]
@@ -734,7 +690,7 @@ class Pass(Statement):
class Print(Statement):
"""class representing a Print node"""
- _astroid_fields = ('dest', 'values',)
+ _astng_fields = ('dest', 'values',)
dest = None
values = None
@@ -743,11 +699,11 @@ class Raise(Statement):
"""class representing a Raise node"""
exc = None
if sys.version_info < (3, 0):
- _astroid_fields = ('exc', 'inst', 'tback')
+ _astng_fields = ('exc', 'inst', 'tback')
inst = None
tback = None
else:
- _astroid_fields = ('exc', 'cause')
+ _astng_fields = ('exc', 'cause')
exc = None
cause = None
@@ -761,13 +717,13 @@ class Raise(Statement):
class Return(Statement):
"""class representing a Return node"""
- _astroid_fields = ('value',)
+ _astng_fields = ('value',)
value = None
class Set(NodeNG, Instance, ParentAssignTypeMixin):
"""class representing a Set node"""
- _astroid_fields = ('elts',)
+ _astng_fields = ('elts',)
def __init__(self, elts=None):
if elts is None:
@@ -776,7 +732,7 @@ class Set(NodeNG, Instance, ParentAssignTypeMixin):
self.elts = [const_factory(e) for e in elts]
def pytype(self):
- return '%s.set' % BUILTINS
+ return '%s.set' % BUILTINS_MODULE
def itered(self):
return self.elts
@@ -784,27 +740,27 @@ class Set(NodeNG, Instance, ParentAssignTypeMixin):
class Slice(NodeNG):
"""class representing a Slice node"""
- _astroid_fields = ('lower', 'upper', 'step')
+ _astng_fields = ('lower', 'upper', 'step')
lower = None
upper = None
step = None
-class Starred(NodeNG, ParentAssignTypeMixin):
+class Starred(NodeNG):
"""class representing a Starred node"""
- _astroid_fields = ('value',)
+ _astng_fields = ('value',)
value = None
class Subscript(NodeNG):
"""class representing a Subscript node"""
- _astroid_fields = ('value', 'slice')
+ _astng_fields = ('value', 'slice')
value = None
slice = None
class TryExcept(BlockRangeMixIn, Statement):
"""class representing a TryExcept node"""
- _astroid_fields = ('body', 'handlers', 'orelse',)
+ _astng_fields = ('body', 'handlers', 'orelse',)
body = None
handlers = None
orelse = None
@@ -830,7 +786,7 @@ class TryExcept(BlockRangeMixIn, Statement):
class TryFinally(BlockRangeMixIn, Statement):
"""class representing a TryFinally node"""
- _astroid_fields = ('body', 'finalbody',)
+ _astng_fields = ('body', 'finalbody',)
body = None
finalbody = None
@@ -842,14 +798,14 @@ class TryFinally(BlockRangeMixIn, Statement):
child = self.body[0]
# py2.5 try: except: finally:
if (isinstance(child, TryExcept) and child.fromlineno == self.fromlineno
- and lineno > self.fromlineno and lineno <= child.tolineno):
+ and lineno > self.fromlineno and lineno <= child.tolineno):
return child.block_range(lineno)
return self._elsed_block_range(lineno, self.finalbody)
class Tuple(NodeNG, Instance, ParentAssignTypeMixin):
"""class representing a Tuple node"""
- _astroid_fields = ('elts',)
+ _astng_fields = ('elts',)
def __init__(self, elts=None):
if elts is None:
@@ -858,7 +814,7 @@ class Tuple(NodeNG, Instance, ParentAssignTypeMixin):
self.elts = [const_factory(e) for e in elts]
def pytype(self):
- return '%s.tuple' % BUILTINS
+ return '%s.tuple' % BUILTINS_MODULE
def getitem(self, index, context=None):
return self.elts[index]
@@ -869,13 +825,13 @@ class Tuple(NodeNG, Instance, ParentAssignTypeMixin):
class UnaryOp(NodeNG):
"""class representing an UnaryOp node"""
- _astroid_fields = ('operand',)
+ _astng_fields = ('operand',)
operand = None
class While(BlockRangeMixIn, Statement):
"""class representing a While node"""
- _astroid_fields = ('test', 'body', 'orelse',)
+ _astng_fields = ('test', 'body', 'orelse',)
test = None
body = None
orelse = None
@@ -890,29 +846,23 @@ class While(BlockRangeMixIn, Statement):
class With(BlockRangeMixIn, AssignTypeMixin, Statement):
"""class representing a With node"""
- _astroid_fields = ('items', 'body')
- items = None
+ _astng_fields = ('expr', 'vars', 'body')
+ expr = None
+ vars = None
body = None
def _blockstart_toline(self):
- return self.items[-1][0].tolineno
+ if self.vars:
+ return self.vars.tolineno
+ else:
+ return self.expr.tolineno
- def get_children(self):
- for expr, var in self.items:
- yield expr
- if var:
- yield var
- for elt in self.body:
- yield elt
class Yield(NodeNG):
"""class representing a Yield node"""
- _astroid_fields = ('value',)
+ _astng_fields = ('value',)
value = None
-class YieldFrom(Yield):
- """ Class representing a YieldFrom node. """
-
# constants ##############################################################
CONST_CLS = {
@@ -935,16 +885,19 @@ def _update_const_classes():
_update_const_classes()
def const_factory(value):
- """return an astroid node for a python value"""
- # XXX we should probably be stricter here and only consider stuff in
- # CONST_CLS or do better treatment: in case where value is not in CONST_CLS,
- # we should rather recall the builder on this value than returning an empty
- # node (another option being that const_factory shouldn't be called with something
- # not in CONST_CLS)
- assert not isinstance(value, NodeNG)
+ """return an astng node for a python value"""
+ # since const_factory is called to evaluate content of container (eg list,
+ # tuple), it may be called with some node as argument that should be left
+ # untouched
+ if isinstance(value, NodeNG):
+ return value
try:
return CONST_CLS[value.__class__](value)
except (KeyError, AttributeError):
+ # some constants (like from gtk._gtk) don't have their class in
+ # CONST_CLS, though we can "assert isinstance(value, tuple(CONST_CLS))"
+ if isinstance(value, tuple(CONST_CLS)):
+ return Const(value)
node = EmptyNode()
node.object = value
return node
« no previous file with comments | « third_party/logilab/astng/mixins.py ('k') | third_party/logilab/astng/nodes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698