from decimal import Decimal
from math import prod
from typing import TYPE_CHECKING
result = prod([Decimal(1), Decimal(2)])
if TYPE_CHECKING:
reveal_type(result)
else:
print(type(result))
Test:
$ mypy --version
mypy 1.10.0 (compiled: yes)
$ mypy decimal_prod.py
decimal_prod.py:8: note: Revealed type is "builtins.float"
Success: no issues found in 1 source file
$ python decimal_prod.py
<class 'decimal.Decimal'>
It sounds as if we should use a TypeVar here, but the existing overload makes me a bit anxious. Any fix should include tests to check a few use cases. (But as always: PR welcome!)
Presumably all non-int return types should be a union with Literal[1]. No matter what type the sequence elements are, it is possible to get the integer 1 with an empty sequence:
Presumably all non-int return types should be a union with Literal[1]. No matter what type the sequence elements are, it is possible to get the integer 1 with an empty sequence:
Activity
srittau commented on May 13, 2024
It sounds as if we should use a TypeVar here, but the existing overload makes me a bit anxious. Any fix should include tests to check a few use cases. (But as always: PR welcome!)
Akuli commented on May 13, 2024
Presumably all non-int return types should be a union with Literal[1]. No matter what type the sequence elements are, it is possible to get the integer 1 with an empty sequence:
real-or-random commented on May 16, 2024
And now try:
kalvdans commented on Nov 5, 2025
Fixed by #13572?