8000 Support flexible TypedDict creation/update by ilevkivskyi · Pull Request #15425 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Support flexible TypedDict creation/update #15425

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

Merged
merged 13 commits into from
Jun 26, 2023
Merged
Prev Previous commit
Next Next commit
Update test
  • Loading branch information
ilevkivskyi committed Jun 13, 2023
commit 7b0ecb57c6ab653398fac4a0cfc9b6948edda8a4
6 changes: 3 additions & 3 deletions test-data/unit/check-typeddict.test
Original file line number Diff line number Diff line change
Expand Up @@ -3138,13 +3138,13 @@ def generate(data: DetailsSubset) -> Details:
[typing fixtures/typing-typeddict.pyi]

[case testTypedDictUnpackUntypedDict]
from typing import TypedDict
from typing import Any, Dict, TypedDict

class Bar(TypedDict):
pass

foo: dict = {}
bar: Bar = {**foo} # E: Unsupported type "Dict[Any, Any]" for ** expansion in TypedDict
foo: Dict[str, Any] = {}
bar: Bar = {**foo} # E: Unsupported type "Dict[str, Any]" for ** expansion in TypedDict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this should be allowed; Any means Any.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Ivan that for consistency we can only this if the type is Dict[Any, Any]. However, I'm not sure if Dict[Any, Any] is supported in other contexts (need to double check).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW as far as I know Dict[Any, Any] is not well supported in other TypedDict contexts. I decided to allow Dict[Any, Any] only because I found an example in mypy_primer where Dict[Any, Any] is used specifically in ** context. I think we can allow Dict[Any, Any] in other contexts, e.g. it can be a (non-proper) subtype of all non-total TypedDicts.

[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]

Expand Down
0