Skip to content

More flexible type support for math.prod and math.sumprod #13501

Open
@cake-monotone

Description

@cake-monotone

Also related to #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)])

Mypy Playground Link

I believe it should be followed the type stub of builtins.sum, but I’m not sure what breaking changes this might cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stubs: improvementImprove/refactor existing annotations, other stubs issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions