More flexible type support for `math.prod` and `math.sumprod`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 82
Description
Also related to https://github.com/python/typeshed/issues/11913
Currently, math.prod and math.sumprod do not properly support Decimal, Fraction, complex, or possibly other numeric types. This makes it inconvenient to replace builtins.sum with math.prod in a straightforward manner.
from typing import reveal_type
from fractions import Fraction
from math import prod
a = prod([Fraction(1), Fraction(2)])
reveal_type(a) # it should be Fraction | Literal[1], but float for now
prod([complex(1, 0), complex(1, 2)])
I believe it should be followed the type stub of builtins.sum, but I’m not sure what breaking changes this might cause.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting the type stubs for math.prod and math.sumprod, then compare their behavior with the builtins.sum stub. Use the linked Mypy Playground examples to check Decimal, Fraction, and complex inference, and confirm the resulting types and any compatibility concerns before treating the issue as done.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100