-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Confusing error message when setting item in a heterogeneous dict #2900
Comments
The dictionary is heterogeneous, as it has both integer and dictionary values. In this case mypy infers The error message from mypy isn't very helpful though. For example,
|
I'm not sure there's an easy way to convey this in the error message, but the mypy failure, despite the cryptic warning, led us to better code: bar = dict(yo=3)
bar['yo'] = 5
foo = dict(junk=1, bar=bar) Basically, we built the inner dict first before embedding it into the outer dict. |
EDIT: I was confused and this is wrong. Original: Isn't it a bug to infer the type as
|
@benkuhn Sounds like you have the definition of compatibility backwards. Being compatible is similar to being a subclass, with some added rules regarding The difference between Regardless, inferring |
Oh, whoops! You're right (and I'm convinced the code example probably should issue a type error). |
For posterity, here's the error that I get running the latest (38453c0):
I agree that this is a confusing error. |
@OrenLeaffer are you planning to upstream your changes in OrenLeaffer@0eedd06? |
In the mean time, is there a canonical work-around for this problem? |
Probably you might use |
How about
|
This simple piece of code throws a mypy error:
I've only tested on the last release (0.471)
The text was updated successfully, but these errors were encountered: