Skip to content

Incorrect error when using sum #7908

Closed
Closed
@yhenon

Description

@yhenon

The following sample code shows mypy generating an error when using python's built-in sum(). As far as I can tell, there should be no error here, as dividing an int and a float is valid behavior. This can also be seen by the fact that assigning to an intermediary variable suppresses the error.

from typing import List

X: List[float] = [1.]
B = sum(X)

print(1 / B)       # no error
print(1 / sum(X))  # error: Argument 1 to "sum" has incompatible type "List[float]"; expected "Iterable[int]"

python 3.6.8, mypy version 0.740

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions