Converts a finite Decimal instance to a rational number, exactly.
(cls, dec)
| 181 | |
| 182 | @classmethod |
| 183 | def from_decimal(cls, dec): |
| 184 | """Converts a finite Decimal instance to a rational number, exactly.""" |
| 185 | from decimal import Decimal |
| 186 | if isinstance(dec, numbers.Integral): |
| 187 | dec = Decimal(int(dec)) |
| 188 | elif not isinstance(dec, Decimal): |
| 189 | raise TypeError( |
| 190 | "%s.from_decimal() only takes Decimals, not %r (%s)" % |
| 191 | (cls.__name__, dec, type(dec).__name__)) |
| 192 | return cls(*dec.as_integer_ratio()) |
| 193 | |
| 194 | def as_integer_ratio(self): |
| 195 | """Return the integer ratio as a tuple. |
nothing calls this directly
no test coverage detected