Skip to content

math.sumprod should support a start parameter like sum and math.prod #130270

@cake-monotone

Description

@cake-monotone

Feature or enhancement

Proposal:

math.sumprod should support a start parameter.

# old
def sumprod(p, q, /)

# proposal
def sumprod(p, q, /, *, start=0)

Reason:

from __future__ import annotations

from typing import Any
from math import sumprod

class Foo:
    def __add__(self, other: Any) -> Foo:
        return Foo()

    def __mul__(self, other: Any) -> Foo:
        return Foo()

sumprod([Foo()], [Foo()])
# TypeError: unsupported operand type(s) for +: 'int' and 'Foo'

For now, math.sumprod starts its calculation from 0 by default, and there seems to be no way to customize this value.

I understand that alternatives like itertools.starmap or defining def __radd__(self, o) exist. But I believe sumprod should support a start parameter for consistency with sum and math.prod.

Metadata

Metadata

Assignees

Labels

type-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions