MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Lib/test/test_binop.py:34–47  ·  view source on GitHub ↗

Constructor: Rat([num[, den]]). The arguments must be ints, and default to (0, 1).

(self, num=0, den=1)

Source from the content-addressed store, hash-verified

32 __slots__ = ['_Rat__num', '_Rat__den']
33
34 def __init__(self, num=0, den=1):
35 """Constructor: Rat([num[, den]]).
36
37 The arguments must be ints, and default to (0, 1)."""
38 if not isint(num):
39 raise TypeError("Rat numerator must be int (%r)" % num)
40 if not isint(den):
41 raise TypeError("Rat denominator must be int (%r)" % den)
42 # But the zero is always on
43 if den == 0:
44 raise ZeroDivisionError("zero denominator")
45 g = gcd(den, num)
46 self.__num = int(num//g)
47 self.__den = int(den//g)
48
49 def _get_num(self):
50 """Accessor function for read-only 'num' attribute of Rat."""

Callers

nothing calls this directly

Calls 2

isintFunction · 0.85
gcdFunction · 0.85

Tested by

no test coverage detected