-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Handle assignments to a TypedDict with {**mapping}
correctly
#14946
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
Comments
I'm not an expert on mypy, but I think what is happening with the example is that mypy is inferring the type created on line 11 as a When the type is specified explicitly, the errors from bad type inference are not returned, but the remaining error ( For your use case, is it sufficient to use the syntax |
Yeah, I could get rid of the if foo is None or "a" not in foo:
foo = {"a": False}
foo["b"] = False which is fine for me. I'm fond of the splatsplat syntax though, so I guess I'd like to turn this issue into "Support |
{**mapping}
correctly
@TeamSpen210 thanks for finding those |
Bug Report
I'm not sure what I'm doing wrong, and the error message from mypy doesn't give me too much insight. So this might be a bug, a documentation issue, or a case of me being daft.
To Reproduce
Expected Behavior
From looking at it alone, I expected this snippet to pass mypy without errors. The errors don't depend on
total=False
, it's just easier to write an example that way.Actual Behavior
The
Argument 1 to "update" of "MutableMapping" has incompatible type "Foo"
in particular trips me up. Skipping the assignment in line 11 and returning right away or assigning to something likebaz: Foo
instead reduces the emount of errors toerror: Expected TypedDict key to be string literal
, but I'd like to avoid that if possible.My Environment
mypy.ini
(and other config files): /The text was updated successfully, but these errors were encountered: