cython

Форк
0
/
special_methods_T561_py3.pyx 
63 строки · 1.9 Кб
1
# ticket: t561
2
# tag: py3, warnings
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.)
6

7
__doc__ = u"""
8
    >>> vs0 = VerySpecial(0)
9
    VS __init__ 0
10

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.
14

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__
21
    >>> Li()
22
    Long __long__
23

24
    >>> # As of Python 3, defining __nonzero__ gives you a __bool__ method instead.
25
    >>> vs0_bool = vs0.__bool__
26
    >>> vs0_bool()
27
    VS __nonzero__ 0
28
    False
29
"""
30

31
cdef class VerySpecial:
32
    cdef readonly int value
33

34
    def __init__(self, v):
35
        self.value = v
36
        print "VS __init__ %d" % self.value
37

38
    def __nonzero__(self):
39
        print "VS __nonzero__ %d" % self.value
40

41
    def __oct__(self):
42
        print "VS __oct__ %d" % self.value
43

44
    def __hex__(self):
45
        print "VS __hex__ %d" % self.value
46

47
    def __cmp__(self, other):
48
        print "VS __cmp__ %d %d" % (self.value, other.value)
49

50
    def __div__(self, other):
51
        print "VS __div__ %d %d" % (self.value, other.value)
52

53
    def __idiv__(self, other):
54
        print "VS __idiv__ %d /= %d" % (self.value, other.value)
55

56
cdef class Long:
57
    def __long__(self):
58
        print "Long __long__"
59

60
_WARNINGS = """
61
38:4: __nonzero__ was removed in Python 3; use __bool__ instead
62
57:4: __long__ was removed in Python 3; use __int__ instead
63
"""
64

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.