-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Error when copying list from dict with generic key #1995
Comments
What version of mypy and typeshed are you using? I cannot reproduce this. :-( |
How do I see which version of typeshed do I have? Maybe that's it... In any case, I'm using
|
I'm sorry, I still can't reproduce this, even with 0.4.3. Can you try uninstalling mypy and reinstalling (preferably from the repo)? FWIW if you pip install mypy, the correct version of typeshed should automatically be installed. Do you have MYPYPATH set? Are you sure the code you're testing is exactly what you posted here? |
Ah you know what, now I'm more confused... I made a dict that I thought was effectively the same, but it apparently is not. I updated the issue with the exact dict I'm using in my code. |
Aha, now I understand your issue. Mypy doesn't (yet) understand that different keys can have values of different types. So it understands that a is a dict whose strings are keys and whose values are dicts again, and the latter dicts have string keys, and values that could be:
There's discussion of a feature that would make your code work here: python/typing#28. But it requires more thought. In the meantime I'm going to close this issue as "won't fix" -- if we decide to add this to PEP 484 (or a follow-up PEP) we'll open a mypy task to implement it. |
That makes sense. Thanks for looking into it, I really appreciate it! In the mean time, is there any way to ignore this error, like how |
You can ignore errors on specific lines with # type: ignore # https://github.com/python/typing/issues/28 |
I have a dict inside of a function that's laid out like this:
When I run the code above through
mypy
, I get the errors listed above. Doesmypy
have issues seeing thatattrs
ina[type]
will resolve to a list? Or is there a way to get around this error message?The text was updated successfully, but these errors were encountered: