-
-
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
TypedDict has no key when checking for key #8887
Comments
Coming back to this, it looks like this should be supported by the tagged union pattern documented here: That documentation uses different Literal values on a key, but we should be able to achieve the same thing by testing whether a key exists or not. |
Curiously, I can't even get the documented tagged union functionality to work in a test case, or find any code related to the feature. For example, this still fails:
|
Your second example passes for me when I run mypy on it as a file (didn't try as a test); maybe you need a different fixture or something. You might be interested in #8151 |
Thanks for digging that up, must just have been something wrong with the way I was running the test. I'm sure I've used the feature in my code before. |
I'm closing this issue, as the root cause of the mypy error here is discussed more precisely in #9953 |
Minimal test case:
The code is checking if the key is present, so this should pass correctly, but instead fails with
error: TypedDict "B" has no key 'foo'
.The text was updated successfully, but these errors were encountered: