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)
11
>>> # Python 3 does not use __cmp__, __div__, __idiv__, __oct__ or __hex__;
12
>>> # These methods have no special behaviour and aren't tested beyond that
13
>>> # they don't break compilation.
15
>>> # Python 3 does not use __long__; if you define __long__ but not
16
>>> # __int__, the __long__ definition will be used for __int__.
17
>>> Ll = Long().__long__ # doctest: +ELLIPSIS
18
Traceback (most recent call last):
19
AttributeError: 'special_methods_T561_py3.Long' object has no attribute '__long__'...
20
>>> Li = Long().__int__
24
>>> # As of Python 3, defining __nonzero__ gives you a __bool__ method instead.
25
>>> vs0_bool = vs0.__bool__
31
cdef class VerySpecial:
32
cdef readonly int value
34
def __init__(self, v):
36
print "VS __init__ %d" % self.value
38
def __nonzero__(self):
39
print "VS __nonzero__ %d" % self.value
42
print "VS __oct__ %d" % self.value
45
print "VS __hex__ %d" % self.value
47
def __cmp__(self, other):
48
print "VS __cmp__ %d %d" % (self.value, other.value)
50
def __div__(self, other):
51
print "VS __div__ %d %d" % (self.value, other.value)
53
def __idiv__(self, other):
54
print "VS __idiv__ %d /= %d" % (self.value, other.value)
61
38:4: __nonzero__ was removed in Python 3; use __bool__ instead
62
57:4: __long__ was removed in Python 3; use __int__ instead