Skip to content

Incorrect error when using sum #7908

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

Closed
yhenon opened this issue Nov 8, 2019 · 3 comments
Closed

Incorrect error when using sum #7908

yhenon opened this issue Nov 8, 2019 · 3 comments

Comments

@yhenon
Copy link

yhenon commented Nov 8, 2019

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

@samsont
Copy link

samsont commented Nov 8, 2019

I ran into the same issue. Interestingly, I found that if the numerator is a float, there is also no error. Adding to the above code:

print(1.0 / sum(X)) # no error

@samsont
Copy link

samsont commented Nov 8, 2019

I think this may be the same as ticket #6040

@ilevkivskyi
Copy link
Member

Yes, this is a duplicate of #6040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants