File: pynumber_subtype_conversion.pyx

package info (click to toggle)
cython 3.0.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,092 kB
  • sloc: python: 83,539; ansic: 18,831; cpp: 1,402; xml: 1,031; javascript: 511; makefile: 403; sh: 204; sed: 11
file content (36 lines) | stat: -rw-r--r-- 473 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# mode: run
# tag: python, float, builtin


class MyFloat(float):
    """
    >>> x = MyFloat(1.0)
    >>> x
    1.0
    >>> float(x)
    12.0
    >>> x.float()
    12.0
    """
    def __float__(self):
        return 12.0

    def float(self):
        return float(self)


class MyInt(int):
    """
    >>> x = MyInt(1)
    >>> x
    1
    >>> int(x)
    2
    >>> x.int()
    2
    """
    def __int__(self):
        return 2

    def int(self):
        return int(self)