-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Sum of an iterable of bools is considered to have a bool type #7579
Comments
See #7578 where we recently experimented with ways to address this sort of thing. |
@JelleZijlstra I'm not sure how that's relevant. The problem is that |
@ktbarrett it's relevant because currently we assume that Type checkers already understand that |
Ah, I see the middle commit now. No one seemed to comment on the failure. |
I think the reason this was passing in mypy 0.931 was that the return used to be typed as That You can see an example here: https://mypy-play.net/?mypy=0.941&python=3.10&flags=strict&gist=4b96aaf8e1261db4bf484c0f76138638
|
Not quite. >>> x: list[list[int]] = []
>>> sum(x)
0 |
yes because if you have an empty iterable you never add anything to the start value which is by default 0 😄
|
Sorry, looks like we were saying the same thing in different ways there 😄 |
Yeah, there's some unfortunate disagreement among type checkers at the moment on how to treat literal types 😕 see #7258 for an extended discussion But while the immediate cause of the new error might have been the change from |
Consider the following code
mypy
v0.931 is OK with it and reportsfoo
type asint
mypy
v0.940 warnsThe stub does indeed state
Though it is somewhat unfortunate. I've got beaten by this after updating
mypy
to the latest version.The text was updated successfully, but these errors were encountered: