-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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(List[Literal[0,1]]) is inferred as Literal[0,1] while it should be int #8230
Comments
I do realise there are a bunch of other sum/Literal related issues on typeshed right now, but I figured my example is a particularly simple one showing an issue. |
Thanks! I can also reproduce this using typeshed master. |
I think this one is also relatively easily fixable :) |
|
Bug report
Using sum on a set of Literal ints has an inferred type of the same Literals, instead of inferring the correct more general type of int.
To reproduce
Expected behaviour
The type of a should be inferred as int.
Actual behaviour
The type of a is inferred to be Literal[0,1]. This is the case for mypy==0.940 and onwards. On mypy==0.930 the correct typing of int is inferred. Explicitly annotating a with int also fixes the issue.
Your environment
Mypy version: 0.961 (also tried 0.940)
Mypy command line flags: none
Mypy configuration options from mypy.ini (and other config files): no other config
Python version used: 3.9.1
Operating system and version: Windows 10
Crossposted from python/mypy#13055
The text was updated successfully, but these errors were encountered: