Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
1 import sys
3 info = sys.version_info
4 if info[:3] >= (3, 2, 0):
5 # for Python 3.2 ordinary unittest is fine
6 import unittest as unittest2
7 else:
8 import unittest2
11 try:
12 callable = callable
13 except NameError:
14 def callable(obj):
15 return hasattr(obj, '__call__')
18 inPy3k = sys.version_info[0] == 3
19 with_available = sys.version_info[:2] >= (2, 5)
22 def is_instance(obj, klass):
23 """Version of is_instance that doesn't access __class__"""
24 return issubclass(type(obj), klass)
27 class SomeClass(object):
28 class_attribute = None
30 def wibble(self):
31 pass
34 class X(object):
35 pass
37 try:
38 next = next
39 except NameError:
40 def next(obj):
41 return obj.next()