| Total Complexity | 2 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import decimal |
||
| 2 | import math |
||
| 3 | from types import MappingProxyType |
||
| 4 | from typing import NewType, Union |
||
| 5 | |||
| 6 | InfNumber = NewType("InfNumber", Union[float, int, decimal.Decimal]) |
||
| 7 | |||
| 8 | INFINITY_MAPPER = MappingProxyType({ |
||
| 9 | 'Infinity': math.inf, |
||
| 10 | '+Infinity': math.inf, |
||
| 11 | '-Infinity': -math.inf |
||
| 12 | }) |
||
| 13 | |||
| 14 | MATH_INF_MAPPER = MappingProxyType({ |
||
| 15 | math.inf: 'Infinity', |
||
| 16 | -math.inf: '-Infinity' |
||
| 17 | }) |
||
| 18 | |||
| 19 | |||
| 20 | def value_to_infnum(value: any) -> InfNumber: |
||
| 21 | return INFINITY_MAPPER.get(value, value) |
||
| 22 | |||
| 23 | |||
| 24 | def infnum_to_value(value: InfNumber): |
||
| 25 | return MATH_INF_MAPPER.get(value, value) |
||
| 26 | |||
| 27 | |||
| 28 | __all__ = ['InfNumber', 'infnum_to_value', 'value_to_infnum'] |
||
| 29 |