Skip to content

DecimalTuple definition is incorrect #9191

Closed
@dapper91

Description

@dapper91

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions