Index: bindings/python/llvm/core.py =================================================================== --- bindings/python/llvm/core.py +++ bindings/python/llvm/core.py @@ -19,6 +19,8 @@ from ctypes import c_char_p from ctypes import c_uint +import sys + __all__ = [ "lib", "Enums", @@ -236,16 +238,19 @@ def __iter__(self): return self - def next(self): + def __next__(self): if not isinstance(self.function, Function): raise StopIteration("") result = self.function if self.reverse: self.function = self.function.prev else: - self.function = self.function.next + self.function = self.function.__next__ return result - + + if sys.version_info.major == 2: + next = __next__ + def __iter__(self): return Module.__function_iterator(self) @@ -304,15 +309,18 @@ def __iter__(self): return self - def next(self): + def __next__(self): if not isinstance(self.bb, BasicBlock): raise StopIteration("") result = self.bb if self.reverse: self.bb = self.bb.prev else: - self.bb = self.bb.next + self.bb = self.bb.__next__ return result + + if sys.version_info.major == 2: + next = __next__ def __iter__(self): return Function.__bb_iterator(self) @@ -381,16 +389,19 @@ def __iter__(self): return self - def next(self): + def __next__(self): if not isinstance(self.inst, Instruction): raise StopIteration("") result = self.inst if self.reverse: self.inst = self.inst.prev else: - self.inst = self.inst.next + self.inst = self.inst.__next__ return result - + + if sys.version_info.major == 2: + next = __next__ + def __iter__(self): return BasicBlock.__inst_iterator(self) Index: bindings/python/llvm/tests/test_core.py =================================================================== --- bindings/python/llvm/tests/test_core.py +++ bindings/python/llvm/tests/test_core.py @@ -98,7 +98,7 @@ f = m.first while f.name != "f6": - f = f.next + f = f.__next__ # Forward for bb in f: Index: utils/gdb-scripts/prettyprinters.py =================================================================== --- utils/gdb-scripts/prettyprinters.py +++ utils/gdb-scripts/prettyprinters.py @@ -1,4 +1,5 @@ from __future__ import print_function +import sys import gdb.printing @@ -6,9 +7,9 @@ def __iter__(self): return self - # Python 2 compatibility - def next(self): - return self.__next__() + if sys.version_info.major == 2: + def next(self): + return self.__next__() def children(self): return self @@ -70,7 +71,7 @@ def __iter__(self): return self - def next(self): + def __next__(self): if self.cur == self.end: raise StopIteration count = self.count @@ -79,13 +80,12 @@ self.cur = self.cur + 1 return '[%d]' % count, cur.dereference() - __next__ = next + if sys.version_info.major == 2: + next = __next__ def __init__(self, val): self.val = val - __next__ = next - def children(self): data = self.val['Data'] return self._iterator(data, data + self.val['Length']) @@ -169,7 +169,7 @@ while self.cur != self.end and (is_equal(self.cur.dereference()['first'], empty) or is_equal(self.cur.dereference()['first'], tombstone)): self.cur = self.cur + 1 - def next(self): + def __next__(self): if self.cur == self.end: raise StopIteration cur = self.cur @@ -182,7 +182,8 @@ self.first = False return 'x', v - __next__ = next + if sys.version_info.makor == 2: + next = __next__ def __init__(self, val): self.val = val