3 # This file tests the behavior of special methods under Python 3
4 # after #561. (Only methods whose behavior differs between Python 2 and 3
5 # are tested here; see special_methods_T561.pyx for the rest of the tests.)
8 >>> vs0 = VerySpecial(0)
10 >>> # Python 3 does not use __cmp__, so any provided __cmp__ method is
11 >>> # discarded under Python 3.
12 >>> vs0_cmp = vs0.__cmp__
13 Traceback (most recent call last):
15 AttributeError: 'special_methods_T561_py3.VerySpecial' object has no attribute '__cmp__'
16 >>> # Python 3 does not use __div__ or __idiv__, so these methods are
17 >>> # discarded under Python 3.
18 >>> vs0_div = vs0.__div__
19 Traceback (most recent call last):
21 AttributeError: 'special_methods_T561_py3.VerySpecial' object has no attribute '__div__'
22 >>> vs0_rdiv = vs0.__rdiv__
23 Traceback (most recent call last):
25 AttributeError: 'special_methods_T561_py3.VerySpecial' object has no attribute '__rdiv__'
26 >>> vs0_idiv = vs0.__idiv__
27 Traceback (most recent call last):
29 AttributeError: 'special_methods_T561_py3.VerySpecial' object has no attribute '__idiv__'
30 >>> # Python 3 does not use __oct__ or __hex__, so these methods are
31 >>> # discarded under Python 3.
32 >>> vs0_oct = vs0.__oct__
33 Traceback (most recent call last):
35 AttributeError: 'special_methods_T561_py3.VerySpecial' object has no attribute '__oct__'
36 >>> vs0_hex = vs0.__hex__
37 Traceback (most recent call last):
39 AttributeError: 'special_methods_T561_py3.VerySpecial' object has no attribute '__hex__'
40 >>> # Python 3 does not use __long__; if you define __long__ but not
41 >>> # __int__, the __long__ definition will be used for __int__.
42 >>> Ll = Long().__long__
43 Traceback (most recent call last):
45 AttributeError: 'special_methods_T561_py3.Long' object has no attribute '__long__'
46 >>> Li = Long().__int__
49 >>> # As of Python 3, defining __nonzero__ gives you a __bool__ method
51 >>> vs0_bool = vs0.__bool__
57 cdef class VerySpecial:
58 cdef readonly int value
60 def __init__(self, v):
62 print "VS __init__ %d" % self.value
64 def __nonzero__(self):
65 print "VS __nonzero__ %d" % self.value
68 print "VS __oct__ %d" % self.value
71 print "VS __hex__ %d" % self.value
73 def __cmp__(self, other):
74 print "VS __cmp__ %d %d" % (self.value, other.value)
76 def __div__(self, other):
77 print "VS __div__ %d %d" % (self.value, other.value)
79 def __idiv__(self, other):
80 print "VS __idiv__ %d /= %d" % (self.value, other.value)