Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecimalTuple definition is incorrect #9191

Closed
dapper91 opened this issue Nov 13, 2022 · 1 comment · Fixed by #9194
Closed

DecimalTuple definition is incorrect #9191

dapper91 opened this issue Nov 13, 2022 · 1 comment · Fixed by #9194

Comments

@dapper91
Copy link

dapper91 commented Nov 13, 2022

Current DecimalTuple definition is:

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:

>>> 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]
@JelleZijlstra
Copy link
Member

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"].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants