mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Regression for TypedDict default getattr

Open ilinum opened this issue 3 years ago • 4 comments

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 avatar Jan 20 '23 22:01 ilinum

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

hauntsaninja avatar Jan 20 '23 22:01 hauntsaninja

cc @ilevkivskyi

hauntsaninja avatar Jan 20 '23 22:01 hauntsaninja

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

ilinum avatar Jan 20 '23 22:01 ilinum

My PR just exposes existing issues (lack of proper union handling) like https://github.com/python/mypy/issues/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.

ilevkivskyi avatar Jan 20 '23 23:01 ilevkivskyi