More flexible type support for `math.prod` and `math.sumprod`
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 5.1k
- Forks
- 2.1k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 82
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Untersuchung der Type Stubs für math.prod und math.sumprod und vergleiche anschließend ihr Verhalten mit dem Stub von builtins.sum. Verwende die verlinkten Mypy Playground-Beispiele, um die Inferenz für Decimal, Fraction und complex zu überprüfen, und bestätige die resultierenden Typen sowie etwaige Kompatibilitätsbedenken, bevor du das Issue als erledigt betrachtest.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 48/100