Current DecimalTuple definition is:
DecimalTuple
class DecimalTuple(NamedTuple): sign: int digits: tuple[int, ...] exponent: int
source: https://github.com/python/typeshed/blob/main/stdlib/_decimal.pyi#L16
But if a decimal value is NaN the exponent is of type str. The following example illustrate that:
NaN
str
>>> from decimal import Decimal >>> exponent = Decimal('NaN').as_tuple().exponent >>> print(exponent) n >>> print(type(exponent)) <class 'str'> >>>
It seems like the correct definition should be like this:
class DecimalTuple(NamedTuple): sign: int digits: tuple[int, ...] exponent: Union[int, str]
Looks like it can also be N for a signaling NaN and F for infinity. I suppose we could do int | Literal["n", "N", "F"].
N
F
int | Literal["n", "N", "F"]
Activity
JelleZijlstra commentedon Nov 13, 2022
Looks like it can also be
Nfor a signaling NaN andFfor infinity. I suppose we could doint | Literal["n", "N", "F"].