Skip to content
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

Regression for TypedDict default getattr #14481

Closed
ilinum opened this issue Jan 20, 2023 · 4 comments · Fixed by #14505
Closed

Regression for TypedDict default getattr #14481

ilinum opened this issue Jan 20, 2023 · 4 comments · Fixed by #14505
Labels
bug mypy got something wrong

Comments

@ilinum
Copy link
Collaborator

ilinum commented Jan 20, 2023

This generates an error on latest error but not on mypy 0.991

from typing import TypedDict

D = TypedDict("D", {"foo": int}, total=False)


def f(d: dict[str, D]) -> None:
    args = d["a"]
    args.update(d.get("b", {}))
@ilinum ilinum added the bug mypy got something wrong label Jan 20, 2023
@hauntsaninja
Copy link
Collaborator

mypy_primer -p test.py --bisect --debug --old v0.991 bisects this to #14178

@hauntsaninja
Copy link
Collaborator

cc @ilevkivskyi

@ilinum
Copy link
Collaborator Author

ilinum commented Jan 20, 2023

Woah, I didn't know you could use mypy-primer in this way! I'll try it on the other regression. Thanks!

@ilevkivskyi
Copy link
Member

My PR just exposes existing issues (lack of proper union handling) like #13274. This is not easy to fix, since plugin for update() returns a TypedDict with no required keys. So even though this particular case will be fixed if we tweak equality for TypedDicts by ignoring fallback, it is easy to construct an example, that will still fail with the same errors.

@ilinum ilinum mentioned this issue Jan 21, 2023
17 tasks
JukkaL pushed a commit that referenced this issue Jan 23, 2023
Fixes #14481 (regression)
Fixes #13274
Fixes #8533

Most notably, if literal matches multiple items in union, it is not an
error, it is only an error if it matches none of them, so I adjust the
error message accordingly.

An import caveat is that an unrelated error like `{"key": 42 + "no"}`
can cause no item to match (an hence an extra error), but I think it is
fine, since we still show the actual error, and avoiding this would
require some dirty hacks.

Also note there was an (obvious) bug in one of the fixtures, that caused
one of repros not repro in tests, fixing it required tweaking an
unrelated test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants