summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--__pkginfo__.py2
-rw-r--r--bases.py2
-rw-r--r--brain/py2stdlib.py2
-rw-r--r--builder.py6
-rw-r--r--inference.py4
-rw-r--r--manager.py17
-rw-r--r--mixins.py2
-rw-r--r--node_classes.py9
-rw-r--r--protocols.py2
-rw-r--r--raw_building.py10
-rw-r--r--scoped_nodes.py30
-rw-r--r--setup.py7
-rw-r--r--test/unittest_brain.py4
-rw-r--r--test/unittest_builder.py13
-rw-r--r--test/unittest_inference.py188
-rw-r--r--test/unittest_lookup.py51
-rw-r--r--test/unittest_modutils.py4
-rw-r--r--test/unittest_nodes.py12
-rw-r--r--test/unittest_regrtest.py8
-rw-r--r--test/unittest_scoped_nodes.py21
-rw-r--r--utils.py19
21 files changed, 206 insertions, 207 deletions
diff --git a/__pkginfo__.py b/__pkginfo__.py
index b601f29..3482020 100644
--- a/__pkginfo__.py
+++ b/__pkginfo__.py
@@ -24,7 +24,7 @@ modname = 'astroid'
numversion = (1, 2, 1)
version = '.'.join([str(num) for num in numversion])
-install_requires = ['logilab-common >= 0.60.0']
+install_requires = ['logilab-common >= 0.60.0', 'six']
license = 'LGPL'
diff --git a/bases.py b/bases.py
index 91ea91b..f1f4cc4 100644
--- a/bases.py
+++ b/bases.py
@@ -578,7 +578,7 @@ class NodeNG(object):
_node = self
try:
while line is None:
- _node = _node.get_children().next()
+ _node = next(_node.get_children())
line = _node.lineno
except StopIteration:
_node = self.parent
diff --git a/brain/py2stdlib.py b/brain/py2stdlib.py
index 92c783b..74d6028 100644
--- a/brain/py2stdlib.py
+++ b/brain/py2stdlib.py
@@ -26,7 +26,7 @@ def infer_func_form(node, base_type, context=None, enum=False):
"""Specific inference function for namedtuple or Python 3 enum. """
def infer_first(node):
try:
- value = node.infer(context=context).next()
+ value = next(node.infer(context=context))
if value is YES:
raise UseInferenceDefault()
else:
diff --git a/builder.py b/builder.py
index 692016a..4e0e225 100644
--- a/builder.py
+++ b/builder.py
@@ -116,12 +116,12 @@ class AstroidBuilder(InspectBuilder):
"""
try:
_, encoding, data = open_source_file(path)
- except IOError, exc:
+ except IOError as exc:
msg = 'Unable to load file %r (%s)' % (path, exc)
raise AstroidBuildingException(msg)
- except SyntaxError, exc: # py3k encoding specification error
+ except SyntaxError as exc: # py3k encoding specification error
raise AstroidBuildingException(exc)
- except LookupError, exc: # unknown encoding
+ except LookupError as exc: # unknown encoding
raise AstroidBuildingException(exc)
# get module name if necessary
if modname is None:
diff --git a/inference.py b/inference.py
index 3f216dd..6cd4b78 100644
--- a/inference.py
+++ b/inference.py
@@ -265,12 +265,12 @@ nodes.Global._infer = path_wrapper(infer_global)
def infer_subscript(self, context=None):
"""infer simple subscription such as [1,2,3][0] or (1,2,3)[-1]"""
- value = self.value.infer(context).next()
+ value = next(self.value.infer(context))
if value is YES:
yield YES
return
- index = self.slice.infer(context).next()
+ index = next(self.slice.infer(context))
if index is YES:
yield YES
return
diff --git a/manager.py b/manager.py
index fde52e2..e1660e4 100644
--- a/manager.py
+++ b/manager.py
@@ -19,6 +19,7 @@
possible by providing a class responsible to get astroid representation
from various source and using a cache of built modules)
"""
+from __future__ import print_function
__docformat__ = "restructuredtext en"
@@ -36,12 +37,12 @@ from astroid.modutils import NoSourceFile, is_python_source, \
def astroid_wrapper(func, modname):
"""wrapper to give to AstroidManager.project_from_files"""
- print 'parsing %s...' % modname
+ print('parsing %s...' % modname)
try:
return func(modname)
- except AstroidBuildingException, exc:
- print exc
- except Exception, exc:
+ except AstroidBuildingException as exc:
+ print(exc)
+ except Exception as exc:
import traceback
traceback.print_exc()
@@ -128,7 +129,7 @@ class AstroidManager(OptionsProviderMixIn):
if filepath is None or not is_python_source(filepath):
try:
module = load_module_from_name(modname)
- except Exception, ex:
+ except Exception as ex:
msg = 'Unable to load module %s (%s)' % (modname, ex)
raise AstroidBuildingException(msg)
return self.ast_from_module(module, modname)
@@ -165,7 +166,7 @@ class AstroidManager(OptionsProviderMixIn):
try:
value = file_from_modpath(modname.split('.'),
context_file=contextfile)
- except ImportError, ex:
+ except ImportError as ex:
msg = 'Unable to load module %s (%s)' % (modname, ex)
value = AstroidBuildingException(msg)
self._mod_file_cache[(modname, contextfile)] = value
@@ -211,7 +212,7 @@ class AstroidManager(OptionsProviderMixIn):
except AttributeError:
raise AstroidBuildingException(
'Unable to get module for %s' % safe_repr(klass))
- except Exception, ex:
+ except Exception as ex:
raise AstroidBuildingException(
'Unexpected error while retrieving module for %s: %s'
% (safe_repr(klass), ex))
@@ -220,7 +221,7 @@ class AstroidManager(OptionsProviderMixIn):
except AttributeError:
raise AstroidBuildingException(
'Unable to get name for %s' % safe_repr(klass))
- except Exception, ex:
+ except Exception as ex:
raise AstroidBuildingException(
'Unexpected error while retrieving name for %s: %s'
% (safe_repr(klass), ex))
diff --git a/mixins.py b/mixins.py
index 1b34c40..dbf1673 100644
--- a/mixins.py
+++ b/mixins.py
@@ -107,7 +107,7 @@ class FromImportMixIn(FilterStmtsMixin):
return mymodule.import_module(modname, level=level)
except AstroidBuildingException:
raise InferenceError(modname)
- except SyntaxError, ex:
+ except SyntaxError as ex:
raise InferenceError(str(ex))
def real_name(self, asname):
diff --git a/node_classes.py b/node_classes.py
index 13376d1..71e512f 100644
--- a/node_classes.py
+++ b/node_classes.py
@@ -20,6 +20,7 @@
import sys
+import six
from logilab.common.decorators import cachedproperty
from astroid.exceptions import NoDefault
@@ -41,7 +42,7 @@ def unpack_infer(stmt, context=None):
yield infered_elt
return
# if infered is a final node, return it and stop
- infered = stmt.infer(context).next()
+ infered = next(stmt.infer(context))
if infered is stmt:
yield infered
return
@@ -495,7 +496,7 @@ class Const(NodeNG, Instance):
self.value = value
def getitem(self, index, context=None):
- if isinstance(self.value, basestring):
+ if isinstance(self.value, six.string_types):
return Const(self.value[index])
raise TypeError('%r (value=%s)' % (self, self.value))
@@ -503,7 +504,7 @@ class Const(NodeNG, Instance):
return False
def itered(self):
- if isinstance(self.value, basestring):
+ if isinstance(self.value, six.string_types):
return self.value
raise TypeError()
@@ -548,7 +549,7 @@ class Dict(NodeNG, Instance):
self.items = []
else:
self.items = [(const_factory(k), const_factory(v))
- for k, v in items.iteritems()]
+ for k, v in items.items()]
def pytype(self):
return '%s.dict' % BUILTINS
diff --git a/protocols.py b/protocols.py
index cc28428..4dd515f 100644
--- a/protocols.py
+++ b/protocols.py
@@ -91,7 +91,7 @@ BIN_OP_IMPL = {'+': lambda a, b: a + b,
'<<': lambda a, b: a << b,
'>>': lambda a, b: a >> b,
}
-for key, impl in BIN_OP_IMPL.items():
+for key, impl in list(BIN_OP_IMPL.items()):
BIN_OP_IMPL[key+'='] = impl
def const_infer_binary_op(self, operator, other, context):
diff --git a/raw_building.py b/raw_building.py
index feded4e..08f6af6 100644
--- a/raw_building.py
+++ b/raw_building.py
@@ -25,6 +25,7 @@ import sys
from os.path import abspath
from inspect import (getargspec, isdatadescriptor, isfunction, ismethod,
ismethoddescriptor, isclass, isbuiltin, ismodule)
+import six
from astroid.node_classes import CONST_CLS
from astroid.nodes import (Module, Class, Const, const_factory, From,
@@ -250,10 +251,11 @@ class InspectBuilder(object):
attach_dummy_node(node, name)
continue
if ismethod(member):
- member = member.im_func
+ member = six.get_method_function(member)
if isfunction(member):
# verify this is not an imported function
- filename = getattr(member.func_code, 'co_filename', None)
+ filename = getattr(six.get_function_code(member),
+ 'co_filename', None)
if filename is None:
assert isinstance(member, object)
object_build_methoddescriptor(node, member, name)
@@ -264,8 +266,6 @@ class InspectBuilder(object):
elif isbuiltin(member):
if (not _io_discrepancy(member) and
self.imported_member(node, member, name)):
- #if obj is object:
- # print 'skippp', obj, name, member
continue
object_build_methoddescriptor(node, member, name)
elif isclass(member):
@@ -302,7 +302,7 @@ class InspectBuilder(object):
modname = getattr(member, '__module__', None)
except:
# XXX use logging
- print 'unexpected error while building astroid from living object'
+ print('unexpected error while building astroid from living object')
import traceback
traceback.print_exc()
modname = None
diff --git a/scoped_nodes.py b/scoped_nodes.py
index 002a789..b234050 100644
--- a/scoped_nodes.py
+++ b/scoped_nodes.py
@@ -30,6 +30,7 @@ try:
except ImportError:
from cStringIO import StringIO as BytesIO
+import six
from logilab.common.compat import builtins
from logilab.common.decorators import cached, cachedproperty
@@ -191,7 +192,7 @@ class LocalsDictNodeNG(LookupMixIn, NodeNG):
"""method from the `dict` interface returning a tuple containing
locally defined names
"""
- return self.locals.keys()
+ return list(self.locals.keys())
def values(self):
"""method from the `dict` interface returning a tuple containing
@@ -204,7 +205,7 @@ class LocalsDictNodeNG(LookupMixIn, NodeNG):
containing each locally defined name with its associated node,
which is an instance of `Function` or `Class`
"""
- return zip(self.keys(), self.values())
+ return list(zip(self.keys(), self.values()))
def __contains__(self, name):
@@ -418,7 +419,7 @@ class Module(LocalsDictNodeNG):
except KeyError:
return [name for name in self.keys() if not name.startswith('_')]
try:
- explicit = all.assigned_stmts().next()
+ explicit = next(all.assigned_stmts())
except InferenceError:
return [name for name in self.keys() if not name.startswith('_')]
except AttributeError:
@@ -492,7 +493,7 @@ def _infer_decorator_callchain(node):
while True:
if isinstance(current, CallFunc):
try:
- current = current.func.infer().next()
+ current = next(current.func.infer())
except InferenceError:
return
elif isinstance(current, Function):
@@ -502,7 +503,7 @@ def _infer_decorator_callchain(node):
# TODO: We don't handle multiple inference results right now,
# because there's no flow to reason when the return
# is what we are looking for, a static or a class method.
- result = current.infer_call_result(current.parent).next()
+ result = next(current.infer_call_result(current.parent))
if current is result:
# This will lead to an infinite loop, where a decorator
# returns itself.
@@ -708,7 +709,7 @@ class Function(Statement, Lambda):
if self.decorators:
for node in self.decorators.nodes:
try:
- infered = node.infer().next()
+ infered = next(node.infer())
except InferenceError:
continue
if infered and infered.qname() in ('abc.abstractproperty',
@@ -729,11 +730,8 @@ class Function(Statement, Lambda):
def is_generator(self):
"""return true if this is a generator function"""
# XXX should be flagged, not computed
- try:
- return self.nodes_of_class((Yield, YieldFrom),
- skip_klass=(Function, Lambda)).next()
- except StopIteration:
- return False
+ return next(self.nodes_of_class((Yield, YieldFrom),
+ skip_klass=(Function, Lambda)), False)
def infer_call_result(self, caller, context=None):
"""infer what a function is returning when called"""
@@ -821,7 +819,6 @@ def _class_type(klass, ancestors=None):
klass._type = 'class'
return 'class'
ancestors.add(klass)
- # print >> sys.stderr, '_class_type', repr(klass)
for base in klass.ancestors(recurs=False):
name = _class_type(base, ancestors)
if name != 'class':
@@ -926,14 +923,15 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
def infer_call_result(self, caller, context=None):
"""infer what a class is returning when called"""
if self._is_subtype_of('%s.type' % (BUILTINS,)) and len(caller.args) == 3:
- name_node = caller.args[0].infer().next()
- if isinstance(name_node, Const) and isinstance(name_node.value, basestring):
+ name_node = next(caller.args[0].infer())
+ if (isinstance(name_node, Const) and
+ isinstance(name_node.value, six.string_types)):
name = name_node.value
else:
yield YES
return
result = Class(name, None)
- bases = caller.args[1].infer().next()
+ bases = next(caller.args[1].infer())
if isinstance(bases, (Tuple, List)):
result.bases = bases.itered()
else:
@@ -1212,7 +1210,7 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
return None
try:
- infered = assignment.infer().next()
+ infered = next(assignment.infer())
except InferenceError:
return
if infered is YES: # don't expose this
diff --git a/setup.py b/setup.py
index a654be1..a117315 100644
--- a/setup.py
+++ b/setup.py
@@ -37,12 +37,7 @@ except ImportError:
from distutils.command import install_lib
USE_SETUPTOOLS = 0
-try:
- # python3
- from distutils.command.build_py import build_py_2to3 as build_py
-except ImportError:
- # python2.x
- from distutils.command.build_py import build_py
+from distutils.command.build_py import build_py
sys.modules.pop('__pkginfo__', None)
# import optional features
diff --git a/test/unittest_brain.py b/test/unittest_brain.py
index 9c8d8e2..8bff310 100644
--- a/test/unittest_brain.py
+++ b/test/unittest_brain.py
@@ -75,7 +75,7 @@ class NamedTupleTest(TestCase):
def foo(fields):
return __(namedtuple("foo", fields))
""")
- self.assertIs(bases.YES, klass.infer().next())
+ self.assertIs(bases.YES, next(klass.infer()))
def test_namedtuple_advanced_inference(self):
@@ -88,7 +88,7 @@ class NamedTupleTest(TestCase):
result = __(urlparse.urlparse('gopher://'))
""")
- instance = result.infer().next()
+ instance = next(result.infer())
self.assertEqual(len(instance.getattr('scheme')), 1)
self.assertEqual(len(instance.getattr('port')), 1)
with self.assertRaises(astroid.NotFoundError):
diff --git a/test/unittest_builder.py b/test/unittest_builder.py
index a0d8d7d..e8c2dfa 100644
--- a/test/unittest_builder.py
+++ b/test/unittest_builder.py
@@ -20,6 +20,7 @@
import unittest
import sys
from os.path import join, abspath, dirname
+from functools import partial
from logilab.common.testlib import TestCase, unittest_main
from pprint import pprint
@@ -449,7 +450,7 @@ def global_no_effect():
self.assertRaises(NotFoundError,
astroid.getattr, 'CSTE2')
self.assertRaises(InferenceError,
- astroid['global_no_effect'].ilookup('CSTE2').next)
+ partial(next, astroid['global_no_effect'].ilookup('CSTE2')))
def test_socket_build(self):
import socket
@@ -570,16 +571,16 @@ class FileBuildTC(TestCase):
klass2 = module['YOUPI']
locals2 = klass2.locals
keys = locals2.keys()
- keys.sort()
- self.assertEqual(keys, ['__init__', 'class_attr', 'class_method',
- 'method', 'static_method'])
+ self.assertEqual(sorted(keys),
+ ['__init__', 'class_attr', 'class_method',
+ 'method', 'static_method'])
def test_class_instance_attrs(self):
module = self.module
klass1 = module['YO']
klass2 = module['YOUPI']
- self.assertEqual(klass1.instance_attrs.keys(), ['yo'])
- self.assertEqual(klass2.instance_attrs.keys(), ['member'])
+ self.assertEqual(list(klass1.instance_attrs.keys()), ['yo'])
+ self.assertEqual(list(klass2.instance_attrs.keys()), ['member'])
def test_class_basenames(self):
module = self.module
diff --git a/test/unittest_inference.py b/test/unittest_inference.py
index a588381..c884f42 100644
--- a/test/unittest_inference.py
+++ b/test/unittest_inference.py
@@ -19,9 +19,11 @@
"""
from os.path import join, dirname, abspath
import sys
-from StringIO import StringIO
+from functools import partial
from textwrap import dedent
+import six
+
from logilab.common.testlib import TestCase, unittest_main, require_version
from astroid import InferenceError, builder, nodes
@@ -33,7 +35,7 @@ def get_name_node(start_from, name, index=0):
return [n for n in start_from.nodes_of_class(nodes.Name) if n.name == name][index]
def get_node_of_class(start_from, klass):
- return start_from.nodes_of_class(klass).next()
+ return next(start_from.nodes_of_class(klass))
builder = builder.AstroidBuilder()
@@ -45,8 +47,8 @@ class InferenceUtilsTC(TestCase):
infer_default = path_wrapper(infer_default)
infer_end = path_wrapper(inference_infer_end)
self.assertRaises(InferenceError,
- infer_default(1).next)
- self.assertEqual(infer_end(1).next(), 1)
+ partial(next, infer_default(1)))
+ self.assertEqual(next(infer_end(1)), 1)
if sys.version_info < (3, 0):
EXC_MODULE = 'exceptions'
@@ -96,186 +98,186 @@ a, b= b, a # Gasp !
def test_module_inference(self):
infered = self.astroid.infer()
- obj = infered.next()
+ obj = next(infered)
self.assertEqual(obj.name, __name__)
self.assertEqual(obj.root().name, __name__)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_class_inference(self):
infered = self.astroid['C'].infer()
- obj = infered.next()
+ obj = next(infered)
self.assertEqual(obj.name, 'C')
self.assertEqual(obj.root().name, __name__)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_function_inference(self):
infered = self.astroid['C']['meth1'].infer()
- obj = infered.next()
+ obj = next(infered)
self.assertEqual(obj.name, 'meth1')
self.assertEqual(obj.root().name, __name__)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_builtin_name_inference(self):
infered = self.astroid['C']['meth1']['var'].infer()
- var = infered.next()
+ var = next(infered)
self.assertEqual(var.name, 'object')
self.assertEqual(var.root().name, BUILTINS)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_tupleassign_name_inference(self):
infered = self.astroid['a'].infer()
- exc = infered.next()
+ exc = next(infered)
self.assertIsInstance(exc, Instance)
self.assertEqual(exc.name, 'Exception')
self.assertEqual(exc.root().name, EXC_MODULE)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
infered = self.astroid['b'].infer()
- const = infered.next()
+ const = next(infered)
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, 1)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
infered = self.astroid['c'].infer()
- const = infered.next()
+ const = next(infered)
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, "bonjour")
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_listassign_name_inference(self):
infered = self.astroid['d'].infer()
- exc = infered.next()
+ exc = next(infered)
self.assertIsInstance(exc, Instance)
self.assertEqual(exc.name, 'Exception')
self.assertEqual(exc.root().name, EXC_MODULE)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
infered = self.astroid['e'].infer()
- const = infered.next()
+ const = next(infered)
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, 1.0)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
infered = self.astroid['f'].infer()
- const = infered.next()
+ const = next(infered)
self.assertIsInstance(const, nodes.Tuple)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_advanced_tupleassign_name_inference1(self):
infered = self.astroid['g'].infer()
- const = infered.next()
+ const = next(infered)
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, "bonjour")
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
infered = self.astroid['h'].infer()
- var = infered.next()
+ var = next(infered)
self.assertEqual(var.name, 'object')
self.assertEqual(var.root().name, BUILTINS)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_advanced_tupleassign_name_inference2(self):
infered = self.astroid['i'].infer()
- const = infered.next()
+ const = next(infered)
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, u"glup")
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
infered = self.astroid['j'].infer()
- const = infered.next()
+ const = next(infered)
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, "bonjour")
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
infered = self.astroid['k'].infer()
- var = infered.next()
+ var = next(infered)
self.assertEqual(var.name, 'object')
self.assertEqual(var.root().name, BUILTINS)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_swap_assign_inference(self):
infered = self.astroid.locals['a'][1].infer()
- const = infered.next()
+ const = next(infered)
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, 1)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
infered = self.astroid.locals['b'][1].infer()
- exc = infered.next()
+ exc = next(infered)
self.assertIsInstance(exc, Instance)
self.assertEqual(exc.name, 'Exception')
self.assertEqual(exc.root().name, EXC_MODULE)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_getattr_inference1(self):
infered = self.astroid['ex'].infer()
- exc = infered.next()
+ exc = next(infered)
self.assertIsInstance(exc, Instance)
self.assertEqual(exc.name, 'Exception')
self.assertEqual(exc.root().name, EXC_MODULE)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_getattr_inference2(self):
infered = get_node_of_class(self.astroid['C']['meth2'], nodes.Getattr).infer()
- meth1 = infered.next()
+ meth1 = next(infered)
self.assertEqual(meth1.name, 'meth1')
self.assertEqual(meth1.root().name, __name__)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_getattr_inference3(self):
infered = self.astroid['C']['meth3']['b'].infer()
- const = infered.next()
+ const = next(infered)
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, 4)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_getattr_inference4(self):
infered = self.astroid['C']['meth3']['c'].infer()
- const = infered.next()
+ const = next(infered)
self.assertIsInstance(const, nodes.Const)
self.assertEqual(const.value, "hop")
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_callfunc_inference(self):
infered = self.astroid['v'].infer()
- meth1 = infered.next()
+ meth1 = next(infered)
self.assertIsInstance(meth1, Instance)
self.assertEqual(meth1.name, 'object')
self.assertEqual(meth1.root().name, BUILTINS)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_unbound_method_inference(self):
infered = self.astroid['m_unbound'].infer()
- meth1 = infered.next()
+ meth1 = next(infered)
self.assertIsInstance(meth1, UnboundMethod)
self.assertEqual(meth1.name, 'meth1')
self.assertEqual(meth1.parent.frame().name, 'C')
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_bound_method_inference(self):
infered = self.astroid['m_bound'].infer()
- meth1 = infered.next()
+ meth1 = next(infered)
self.assertIsInstance(meth1, BoundMethod)
self.assertEqual(meth1.name, 'meth1')
self.assertEqual(meth1.parent.frame().name, 'C')
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_args_default_inference1(self):
optarg = get_name_node(self.astroid['C']['meth1'], 'optarg')
infered = optarg.infer()
- obj1 = infered.next()
+ obj1 = next(infered)
self.assertIsInstance(obj1, nodes.Const)
self.assertEqual(obj1.value, 0)
- obj1 = infered.next()
+ obj1 = next(infered)
self.assertIs(obj1, YES, obj1)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_args_default_inference2(self):
infered = self.astroid['C']['meth3'].ilookup('d')
- obj1 = infered.next()
+ obj1 = next(infered)
self.assertIsInstance(obj1, nodes.Const)
self.assertEqual(obj1.value, 4)
- obj1 = infered.next()
+ obj1 = next(infered)
self.assertIs(obj1, YES, obj1)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_inference_restrictions(self):
infered = get_name_node(self.astroid['C']['meth1'], 'arg1').infer()
- obj1 = infered.next()
+ obj1 = next(infered)
self.assertIs(obj1, YES, obj1)
- self.assertRaises(StopIteration, infered.next)
+ self.assertRaises(StopIteration, partial(next, infered))
def test_ancestors_inference(self):
code = '''
@@ -330,7 +332,7 @@ def f():
raise NotImplementedError
'''
astroid = builder.string_build(code, __name__, __file__)
- error = astroid.nodes_of_class(nodes.Name).next()
+ error = next(astroid.nodes_of_class(nodes.Name))
nie = error.infered()[0]
self.assertIsInstance(nie, nodes.Class)
nie_ancestors = [c.name for c in nie.ancestors()]
@@ -354,16 +356,16 @@ except Exception, ex:
astroid = builder.string_build(code, __name__, __file__)
ex1 = astroid['ex1']
ex1_infer = ex1.infer()
- ex1 = ex1_infer.next()
+ ex1 = next(ex1_infer)
self.assertIsInstance(ex1, Instance)
self.assertEqual(ex1.name, 'NameError')
- self.assertRaises(StopIteration, ex1_infer.next)
+ self.assertRaises(StopIteration, partial(next, ex1_infer))
ex2 = astroid['ex2']
ex2_infer = ex2.infer()
- ex2 = ex2_infer.next()
+ ex2 = next(ex2_infer)
self.assertIsInstance(ex2, Instance)
self.assertEqual(ex2.name, 'Exception')
- self.assertRaises(StopIteration, ex2_infer.next)
+ self.assertRaises(StopIteration, partial(next, ex2_infer))
def test_del1(self):
code = '''
@@ -384,19 +386,19 @@ d = a
astroid = builder.string_build(code, __name__, __file__)
n = astroid['b']
n_infer = n.infer()
- infered = n_infer.next()
+ infered = next(n_infer)
self.assertIsInstance(infered, nodes.Const)
self.assertEqual(infered.value, 1)
- self.assertRaises(StopIteration, n_infer.next)
+ self.assertRaises(StopIteration, partial(next, n_infer))
n = astroid['c']
n_infer = n.infer()
- self.assertRaises(InferenceError, n_infer.next)
+ self.assertRaises(InferenceError, partial(next, n_infer))
n = astroid['d']
n_infer = n.infer()
- infered = n_infer.next()
+ infered = next(n_infer)
self.assertIsInstance(infered, nodes.Const)
self.assertEqual(infered.value, 2)
- self.assertRaises(StopIteration, n_infer.next)
+ self.assertRaises(StopIteration, partial(next, n_infer))
def test_builtin_types(self):
code = '''
@@ -408,7 +410,7 @@ s2 = '_'
'''
astroid = builder.string_build(code, __name__, __file__)
n = astroid['l']
- infered = n.infer().next()
+ infered = next(n.infer())
self.assertIsInstance(infered, nodes.List)
self.assertIsInstance(infered, Instance)
self.assertEqual(infered.getitem(0).value, 1)
@@ -416,27 +418,27 @@ s2 = '_'
self.assertEqual(infered._proxied.name, 'list')
self.assertIn('append', infered._proxied.locals)
n = astroid['t']
- infered = n.infer().next()
+ infered = next(n.infer())
self.assertIsInstance(infered, nodes.Tuple)
self.assertIsInstance(infered, Instance)
self.assertEqual(infered.getitem(0).value, 2)
self.assertIsInstance(infered._proxied, nodes.Class)
self.assertEqual(infered._proxied.name, 'tuple')
n = astroid['d']
- infered = n.infer().next()
+ infered = next(n.infer())
self.assertIsInstance(infered, nodes.Dict)
self.assertIsInstance(infered, Instance)
self.assertIsInstance(infered._proxied, nodes.Class)
self.assertEqual(infered._proxied.name, 'dict')
self.assertIn('get', infered._proxied.locals)
n = astroid['s']
- infered = n.infer().next()
+ infered = next(n.infer())
self.assertIsInstance(infered, nodes.Const)
self.assertIsInstance(infered, Instance)
self.assertEqual(infered.name, 'str')
self.assertIn('lower', infered._proxied.locals)
n = astroid['s2']
- infered = n.infer().next()
+ infered = next(n.infer())
self.assertEqual(infered.getitem(0).value, '_')
@require_version('2.7')
@@ -444,7 +446,7 @@ s2 = '_'
code = 's = {1}'
astroid = builder.string_build(code, __name__, __file__)
n = astroid['s']
- infered = n.infer().next()
+ infered = next(n.infer())
self.assertIsInstance(infered, nodes.Set)
self.assertIsInstance(infered, Instance)
self.assertEqual(infered.name, 'set')
@@ -456,7 +458,7 @@ s2 = '_'
code = '''u = u""'''
astroid = builder.string_build(code, __name__, __file__)
n = astroid['u']
- infered = n.infer().next()
+ infered = next(n.infer())
self.assertIsInstance(infered, nodes.Const)
self.assertIsInstance(infered, Instance)
self.assertEqual(infered.name, 'unicode')
@@ -469,9 +471,9 @@ class A:
clsm = classmethod('whatever')
'''
astroid = builder.string_build(code, __name__, __file__)
- statm = astroid['A'].igetattr('statm').next()
+ statm = next(astroid['A'].igetattr('statm'))
self.assertTrue(statm.callable())
- clsm = astroid['A'].igetattr('clsm').next()
+ clsm = next(astroid['A'].igetattr('clsm'))
self.assertTrue(clsm.callable())
def test_bt_ancestor_crash(self):
@@ -482,19 +484,19 @@ class Warning(Warning):
astroid = builder.string_build(code, __name__, __file__)
w = astroid['Warning']
ancestors = w.ancestors()
- ancestor = ancestors.next()
+ ancestor = next(ancestors)
self.assertEqual(ancestor.name, 'Warning')
self.assertEqual(ancestor.root().name, EXC_MODULE)
- ancestor = ancestors.next()
+ ancestor = next(ancestors)
self.assertEqual(ancestor.name, 'Exception')
self.assertEqual(ancestor.root().name, EXC_MODULE)
- ancestor = ancestors.next()
+ ancestor = next(ancestors)
self.assertEqual(ancestor.name, 'BaseException')
self.assertEqual(ancestor.root().name, EXC_MODULE)
- ancestor = ancestors.next()
+ ancestor = next(ancestors)
self.assertEqual(ancestor.name, 'object')
self.assertEqual(ancestor.root().name, BUILTINS)
- self.assertRaises(StopIteration, ancestors.next)
+ self.assertRaises(StopIteration, partial(next, ancestors))
def test_qqch(self):
code = '''
@@ -544,10 +546,10 @@ def test_view(rql, vid, tags=()):
astroid = builder.string_build(code, __name__, __file__)
name = get_name_node(astroid['test_view'], 'tags', -1)
it = name.infer()
- tags = it.next()
+ tags = next(it)
self.assertEqual(tags.__class__, Instance)
self.assertEqual(tags._proxied.name, 'list')
- self.assertRaises(StopIteration, it.next)
+ self.assertRaises(StopIteration, partial(next, it))
@@ -960,7 +962,7 @@ class Bar(Foo):
self.assertEqual(bar_class.instance_attrs, {'attr': [assattr]})
def test_python25_generator_exit(self):
- sys.stderr = StringIO()
+ sys.stderr = six.StringIO()
data = "b = {}[str(0)+''].a"
astroid = builder.string_build(data, __name__, __file__)
list(astroid['b'].infer())
@@ -974,7 +976,7 @@ class Bar(Foo):
# !! FIXME also this relative import would not work 'in real' (no __init__.py in test/)
# the test works since we pretend we have a package by passing the full modname
astroid = builder.string_build(data, 'astroid.test.unittest_inference', __file__)
- infered = get_name_node(astroid, 'date').infer().next()
+ infered = next(get_name_node(astroid, 'date').infer())
self.assertIsInstance(infered, nodes.Module)
self.assertEqual(infered.name, 'logilab.common.date')
@@ -982,7 +984,7 @@ class Bar(Foo):
fname = join(abspath(dirname(__file__)), 'regrtest_data', 'package', 'absimport.py')
astroid = builder.file_build(fname, 'absimport')
self.assertTrue(astroid.absolute_import_activated(), True)
- infered = get_name_node(astroid, 'import_package_subpackage_module').infer().next()
+ infered = next(get_name_node(astroid, 'import_package_subpackage_module').infer())
# failed to import since absolute_import is activated
self.assertIs(infered, YES)
@@ -990,7 +992,7 @@ class Bar(Foo):
fname = join(abspath(dirname(__file__)), 'regrtest_data', 'absimp', 'string.py')
astroid = builder.file_build(fname, 'absimp.string')
self.assertTrue(astroid.absolute_import_activated(), True)
- infered = get_name_node(astroid, 'string').infer().next()
+ infered = next(get_name_node(astroid, 'string').infer())
self.assertIsInstance(infered, nodes.Module)
self.assertEqual(infered.name, 'string')
self.assertIn('ascii_letters', infered.locals)
@@ -1005,14 +1007,14 @@ print (Browser)
b = Browser()
'''
astroid = builder.string_build(data, __name__, __file__)
- browser = get_name_node(astroid, 'Browser').infer().next()
+ browser = next(get_name_node(astroid, 'Browser').infer())
self.assertIsInstance(browser, nodes.Class)
bopen = list(browser.igetattr('open'))
self.skipTest('the commit said: "huum, see that later"')
self.assertEqual(len(bopen), 1)
self.assertIsInstance(bopen[0], nodes.Function)
self.assertTrue(bopen[0].callable())
- b = get_name_node(astroid, 'b').infer().next()
+ b = next(get_name_node(astroid, 'b').infer())
self.assertIsInstance(b, Instance)
bopen = list(b.igetattr('open'))
self.assertEqual(len(bopen), 1)
@@ -1182,7 +1184,7 @@ n = NewTest()
'''
astroid = builder.string_build(code, __name__, __file__)
self.assertRaises(InferenceError, list, astroid['NewTest'].igetattr('arg'))
- n = astroid['n'].infer().next()
+ n = next(astroid['n'].infer())
infered = list(n.igetattr('arg'))
self.assertEqual(len(infered), 1, infered)
diff --git a/test/unittest_lookup.py b/test/unittest_lookup.py
index c228535..b3c8150 100644
--- a/test/unittest_lookup.py
+++ b/test/unittest_lookup.py
@@ -19,6 +19,7 @@
"""
import sys
from os.path import join, abspath, dirname
+from functools import partial
from logilab.common.testlib import TestCase, unittest_main, require_version
@@ -50,7 +51,7 @@ def func():
'''
astroid = builder.string_build(code, __name__, __file__)
# a & b
- a = astroid.nodes_of_class(nodes.Name).next()
+ a = next(astroid.nodes_of_class(nodes.Name))
self.assertEqual(a.lineno, 2)
if sys.version_info < (3, 0):
self.assertEqual(len(astroid.lookup('b')[1]), 2)
@@ -64,22 +65,22 @@ def func():
self.assertEqual(len(stmts), 1)
self.assertEqual(b.lineno, 6)
b_infer = b.infer()
- b_value = b_infer.next()
+ b_value = next(b_infer)
self.assertEqual(b_value.value, 1)
# c
- self.assertRaises(StopIteration, b_infer.next)
+ self.assertRaises(StopIteration, partial(next, b_infer))
func = astroid.locals['func'][0]
self.assertEqual(len(func.lookup('c')[1]), 1)
def test_module(self):
astroid = builder.string_build('pass', __name__, __file__)
# built-in objects
- none = astroid.ilookup('None').next()
+ none = next(astroid.ilookup('None'))
self.assertIsNone(none.value)
- obj = astroid.ilookup('object').next()
+ obj = next(astroid.ilookup('object'))
self.assertIsInstance(obj, nodes.Class)
self.assertEqual(obj.name, 'object')
- self.assertRaises(InferenceError, astroid.ilookup('YOAA').next)
+ self.assertRaises(InferenceError, partial(next, astroid.ilookup('YOAA')))
# XXX
self.assertEqual(len(list(NONREGR.ilookup('enumerate'))), 2)
@@ -95,22 +96,22 @@ class A(A):
astroid = builder.string_build(code, __name__, __file__)
cls1 = astroid.locals['A'][0]
cls2 = astroid.locals['A'][1]
- name = cls2.nodes_of_class(nodes.Name).next()
- self.assertEqual(name.infer().next(), cls1)
+ name = next(cls2.nodes_of_class(nodes.Name))
+ self.assertEqual(next(name.infer()), cls1)
### backport those test to inline code
def test_method(self):
method = MODULE['YOUPI']['method']
- my_dict = method.ilookup('MY_DICT').next()
+ my_dict = next(method.ilookup('MY_DICT'))
self.assertTrue(isinstance(my_dict, nodes.Dict), my_dict)
- none = method.ilookup('None').next()
+ none = next(method.ilookup('None'))
self.assertIsNone(none.value)
- self.assertRaises(InferenceError, method.ilookup('YOAA').next)
+ self.assertRaises(InferenceError, partial(next, method.ilookup('YOAA')))
def test_function_argument_with_default(self):
make_class = MODULE2['make_class']
- base = make_class.ilookup('base').next()
+ base = next(make_class.ilookup('base'))
self.assertTrue(isinstance(base, nodes.Class), base.__class__)
self.assertEqual(base.name, 'YO')
self.assertEqual(base.root().name, 'data.module')
@@ -118,14 +119,14 @@ class A(A):
def test_class(self):
klass = MODULE['YOUPI']
- my_dict = klass.ilookup('MY_DICT').next()
+ my_dict = next(klass.ilookup('MY_DICT'))
self.assertIsInstance(my_dict, nodes.Dict)
- none = klass.ilookup('None').next()
+ none = next(klass.ilookup('None'))
self.assertIsNone(none.value)
- obj = klass.ilookup('object').next()
+ obj = next(klass.ilookup('object'))
self.assertIsInstance(obj, nodes.Class)
self.assertEqual(obj.name, 'object')
- self.assertRaises(InferenceError, klass.ilookup('YOAA').next)
+ self.assertRaises(InferenceError, partial(next, klass.ilookup('YOAA')))
def test_inner_classes(self):
@@ -246,12 +247,12 @@ class NoName: pass
p3 = NoName()
'''
astroid = builder.string_build(code, __name__, __file__)
- p1 = astroid['p1'].infer().next()
+ p1 = next(astroid['p1'].infer())
self.assertTrue(p1.getattr('__name__'))
- p2 = astroid['p2'].infer().next()
+ p2 = next(astroid['p2'].infer())
self.assertTrue(p2.getattr('__name__'))
self.assertTrue(astroid['NoName'].getattr('__name__'))
- p3 = astroid['p3'].infer().next()
+ p3 = next(astroid['p3'].infer())
self.assertRaises(NotFoundError, p3.getattr, '__name__')
@@ -291,10 +292,10 @@ class foo:
astroid = builder.string_build(code, __name__, __file__)
member = get_name_node(astroid['foo'], 'member')
it = member.infer()
- obj = it.next()
+ obj = next(it)
self.assertIsInstance(obj, nodes.Const)
self.assertEqual(obj.value, 10)
- self.assertRaises(StopIteration, it.next)
+ self.assertRaises(StopIteration, partial(next, it))
def test_inner_decorator_member_lookup(self):
@@ -310,9 +311,9 @@ class FileA:
astroid = builder.string_build(code, __name__, __file__)
decname = get_name_node(astroid['FileA'], 'decorator')
it = decname.infer()
- obj = it.next()
+ obj = next(it)
self.assertIsInstance(obj, nodes.Function)
- self.assertRaises(StopIteration, it.next)
+ self.assertRaises(StopIteration, partial(next, it))
def test_static_method_lookup(self):
@@ -331,9 +332,9 @@ class Test:
'''
astroid = builder.string_build(code, __name__, __file__)
it = astroid['Test']['__init__'].ilookup('FileA')
- obj = it.next()
+ obj = next(it)
self.assertIsInstance(obj, nodes.Class)
- self.assertRaises(StopIteration, it.next)
+ self.assertRaises(StopIteration, partial(next, it))
def test_global_delete(self):
diff --git a/test/unittest_modutils.py b/test/unittest_modutils.py
index a9cd624..8f74060 100644
--- a/test/unittest_modutils.py
+++ b/test/unittest_modutils.py
@@ -39,7 +39,7 @@ class ModuleFileTC(TestCase):
def tearDown(self):
super(ModuleFileTC, self).tearDown()
- for k in sys.path_importer_cache.keys():
+ for k in list(sys.path_importer_cache.keys()):
if 'MyPyPa' in k:
del sys.path_importer_cache[k]
@@ -211,8 +211,6 @@ class is_standard_module_tc(TestCase):
def test_custom_path(self):
if DATADIR.startswith(modutils.EXT_LIB_DIR):
self.skipTest('known breakage of is_standard_module on installed package')
- print repr(DATADIR)
- print modutils.EXT_LIB_DIR
self.assertEqual(modutils.is_standard_module('data.module', (DATADIR,)), True)
self.assertEqual(modutils.is_standard_module('data.module', (path.abspath(DATADIR),)), True)
diff --git a/test/unittest_nodes.py b/test/unittest_nodes.py
index d4f164a..b17004e 100644
--- a/test/unittest_nodes.py
+++ b/test/unittest_nodes.py
@@ -231,14 +231,14 @@ MODULE2 = abuilder.file_build(join(DATA, 'module2.py'), 'data.module2')
class ImportNodeTC(testlib.TestCase):
def test_import_self_resolve(self):
- myos = MODULE2.igetattr('myos').next()
+ myos = next(MODULE2.igetattr('myos'))
self.assertTrue(isinstance(myos, nodes.Module), myos)
self.assertEqual(myos.name, 'os')
self.assertEqual(myos.qname(), 'os')
self.assertEqual(myos.pytype(), '%s.module' % BUILTINS)
def test_from_self_resolve(self):
- pb = MODULE.igetattr('pb').next()
+ pb = next(MODULE.igetattr('pb'))
self.assertTrue(isinstance(pb, nodes.Class), pb)
self.assertEqual(pb.root().name, 'logilab.common.shellutils')
self.assertEqual(pb.qname(), 'logilab.common.shellutils.ProgressBar')
@@ -246,7 +246,7 @@ class ImportNodeTC(testlib.TestCase):
self.assertEqual(pb.pytype(), '%s.type' % BUILTINS)
else:
self.assertEqual(pb.pytype(), '%s.classobj' % BUILTINS)
- abspath = MODULE2.igetattr('abspath').next()
+ abspath = next(MODULE2.igetattr('abspath'))
self.assertTrue(isinstance(abspath, nodes.Function), abspath)
self.assertEqual(abspath.root().name, 'os.path')
self.assertEqual(abspath.qname(), 'os.path.abspath')
@@ -309,8 +309,8 @@ except PickleError:
astroid = abuilder.file_build(self.datapath('absimport.py'))
ctx = InferenceContext()
# will fail if absolute import failed
- astroid['message'].infer(ctx, lookupname='message').next()
- m = astroid['email'].infer(ctx, lookupname='email').next()
+ next(astroid['message'].infer(ctx, lookupname='message'))
+ m = next(astroid['email'].infer(ctx, lookupname='email'))
self.assertFalse(m.file.startswith(self.datapath('email.py')))
def test_more_absolute_import(self):
@@ -390,7 +390,7 @@ x = lambda x: None
''')
self.assertEqual(ast['func'].args.fromlineno, 2)
self.assertFalse(ast['func'].args.is_statement)
- xlambda = ast['x'].infer().next()
+ xlambda = next(ast['x'].infer())
self.assertEqual(xlambda.args.fromlineno, 4)
self.assertEqual(xlambda.args.tolineno, 4)
self.assertFalse(xlambda.args.is_statement)
diff --git a/test/unittest_regrtest.py b/test/unittest_regrtest.py
index df1e5ba..c04ff14 100644
--- a/test/unittest_regrtest.py
+++ b/test/unittest_regrtest.py
@@ -52,13 +52,13 @@ class NonRegressionTC(TestCase):
def test_module_path(self):
man = self.brainless_manager()
mod = man.ast_from_module_name('package.import_package_subpackage_module')
- package = mod.igetattr('package').next()
+ package = next(mod.igetattr('package'))
self.assertEqual(package.name, 'package')
- subpackage = package.igetattr('subpackage').next()
+ subpackage = next(package.igetattr('subpackage'))
self.assertIsInstance(subpackage, nodes.Module)
self.assertTrue(subpackage.package)
self.assertEqual(subpackage.name, 'package.subpackage')
- module = subpackage.igetattr('module').next()
+ module = next(subpackage.igetattr('module'))
self.assertEqual(module.name, 'package.subpackage.module')
@@ -68,7 +68,7 @@ class NonRegressionTC(TestCase):
package = manager.ast_from_module_name('absimp')
self.assertIsInstance(package, nodes.Module)
self.assertTrue(package.package)
- subpackage = package.getattr('sidepackage')[0].infer().next()
+ subpackage = next(package.getattr('sidepackage')[0].infer())
self.assertIsInstance(subpackage, nodes.Module)
self.assertTrue(subpackage.package)
self.assertEqual(subpackage.name, 'absimp.sidepackage')
diff --git a/test/unittest_scoped_nodes.py b/test/unittest_scoped_nodes.py
index 94f3a34..ffb75e8 100644
--- a/test/unittest_scoped_nodes.py
+++ b/test/unittest_scoped_nodes.py
@@ -23,6 +23,7 @@ from __future__ import with_statement
import sys
from os.path import join, abspath, dirname
+from functools import partial
from textwrap import dedent
from logilab.common.testlib import TestCase, unittest_main, require_version
@@ -76,10 +77,10 @@ class ModuleNodeTC(TestCase):
yo = MODULE.getattr('YO')[0]
self.assertIsInstance(yo, nodes.Class)
self.assertEqual(yo.name, 'YO')
- red = MODULE.igetattr('redirect').next()
+ red = next(MODULE.igetattr('redirect'))
self.assertIsInstance(red, nodes.Function)
self.assertEqual(red.name, 'four_args')
- pb = MODULE.igetattr('pb').next()
+ pb = next(MODULE.igetattr('pb'))
self.assertIsInstance(pb, nodes.Class)
self.assertEqual(pb.name, 'ProgressBar')
# resolve packageredirection
@@ -87,8 +88,8 @@ class ModuleNodeTC(TestCase):
mod = abuilder.file_build(join(DATA, 'appl/myConnection.py'),
'appl.myConnection')
try:
- ssl = mod.igetattr('SSL1').next()
- cnx = ssl.igetattr('Connection').next()
+ ssl = next(mod.igetattr('SSL1'))
+ cnx = next(ssl.igetattr('Connection'))
self.assertEqual(cnx.__class__, nodes.Class)
self.assertEqual(cnx.name, 'Connection')
self.assertEqual(cnx.root().name, 'SSL1.Connection1')
@@ -514,23 +515,23 @@ A.__bases__ += (B,)
def test_local_attr_ancestors(self):
klass2 = MODULE['YOUPI']
it = klass2.local_attr_ancestors('__init__')
- anc_klass = it.next()
+ anc_klass = next(it)
self.assertIsInstance(anc_klass, nodes.Class)
self.assertEqual(anc_klass.name, 'YO')
- self.assertRaises(StopIteration, it.next)
+ self.assertRaises(StopIteration, partial(next, it))
it = klass2.local_attr_ancestors('method')
- self.assertRaises(StopIteration, it.next)
+ self.assertRaises(StopIteration, partial(next, it))
def test_instance_attr_ancestors(self):
klass2 = MODULE['YOUPI']
it = klass2.instance_attr_ancestors('yo')
- anc_klass = it.next()
+ anc_klass = next(it)
self.assertIsInstance(anc_klass, nodes.Class)
self.assertEqual(anc_klass.name, 'YO')
- self.assertRaises(StopIteration, it.next)
+ self.assertRaises(StopIteration, partial(next, it))
klass2 = MODULE['YOUPI']
it = klass2.instance_attr_ancestors('member')
- self.assertRaises(StopIteration, it.next)
+ self.assertRaises(StopIteration, partial(next, it))
def test_methods(self):
klass2 = MODULE['YOUPI']
diff --git a/utils.py b/utils.py
index 936c8b5..ae72a92 100644
--- a/utils.py
+++ b/utils.py
@@ -18,6 +18,7 @@
"""this module contains some utilities to navigate in the tree or to
extract information from it
"""
+from __future__ import print_function
__docformat__ = "restructuredtext en"
@@ -109,22 +110,22 @@ def _check_children(node):
for child in node.get_children():
ok = False
if child is None:
- print "Hm, child of %s is None" % node
+ print("Hm, child of %s is None" % node)
continue
if not hasattr(child, 'parent'):
- print " ERROR: %s has child %s %x with no parent" % (
- node, child, id(child))
+ print(" ERROR: %s has child %s %x with no parent" % (
+ node, child, id(child)))
elif not child.parent:
- print " ERROR: %s has child %s %x with parent %r" % (
- node, child, id(child), child.parent)
+ print(" ERROR: %s has child %s %x with parent %r" % (
+ node, child, id(child), child.parent))
elif child.parent is not node:
- print " ERROR: %s %x has child %s %x with wrong parent %s" % (
- node, id(node), child, id(child), child.parent)
+ print(" ERROR: %s %x has child %s %x with wrong parent %s" % (
+ node, id(node), child, id(child), child.parent))
else:
ok = True
if not ok:
- print "lines;", node.lineno, child.lineno
- print "of module", node.root(), node.root().name
+ print("lines;", node.lineno, child.lineno)
+ print("of module", node.root(), node.root().name)
raise AstroidBuildingException
_check_children(child)