Closed socketpair closed 2 years ago
@JelleZijlstra ?
I'm closing this issue. It's very unclear what this code is meant to do, or how you expect mypy to cope with it.
Mypy emits many errors for things which will not necessarily cause type errors at runtime, and this is entirely deliberate.
emm. Why not to ask me (topicstarter) ?
@AlexWaygood Python code in the example has no typing errors. mypy incorrectly thinks that {**value, 'c': False}
is Mapping[str, bool]
Duplicate of #11604 in that case (and probably others)
@socketpair, this stackoverflow Q&A might be helpful: https://stackoverflow.com/questions/68803511/mypy-error-incompatible-types-in-assignment-expression-has-type-dictnothing
The issue is that your code here is pretty dynamic, so mypy doesn't know how to interpret the types of your variables. You can fix the error by adding type annotations.
gives:
but actually works as expected:
https://mypy-play.net/?mypy=latest&python=3.8&gist=b9e421adc95622a33aceae1f2b6fcc6e