Passed
Push — main ( e63dae...c88093 )
by Eran
01:18
created

graphinate.tools.converters   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A infnum_to_str() 0 2 1
A str_to_infnum() 0 2 1
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
})
12
13
MATH_INF_MAPPER = MappingProxyType({
14
    math.inf: 'Infinity',
15
    -math.inf: '-Infinity'
16
})
17
18
19
def str_to_infnum(value: str):
20
    return INFINITY_MAPPER.get(value, value)
21
22
23
def infnum_to_str(value: InfNumber):
24
    return MATH_INF_MAPPER.get(value, value)
25
26
27
__all__ = ['InfNumber', 'infnum_to_str', 'str_to_infnum']
28