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

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

Open
cake-monotone opened this issue Feb 14, 2025 · 3 comments
Open

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

cake-monotone opened this issue Feb 14, 2025 · 3 comments
Labels
stubs: improvement Improve/refactor existing annotations, other stubs issues

Comments

@cake-monotone
Copy link

cake-monotone commented Feb 14, 2025

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.

@cake-monotone
Copy link
Author

cake-monotone commented Feb 14, 2025

@srittau srittau added the stubs: improvement Improve/refactor existing annotations, other stubs issues label Feb 17, 2025
@srittau
Copy link
Collaborator

srittau commented Feb 17, 2025

Any improvements here are welcome!

@cake-monotone
Copy link
Author

Sounds good! I'll work on creating a PR for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: improvement Improve/refactor existing annotations, other stubs issues
Projects
None yet
Development

No branches or pull requests

2 participants