classification
Title: TypedDict(...) as function does not respect "total" when setting __required_keys__ and __optional_keys__
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alex.gronholm, gvanrossum, levkivskyi
Priority: normal Keywords: patch

Created on 2020-10-17 09:23 by alex.gronholm, last changed 2020-10-17 15:09 by gvanrossum.

Pull Requests
URL Status Linked Edit
PR 22736 open alex.gronholm, 2020-10-17 09:39
Messages (3)
msg378805 - (view) Author: Alex Grönholm (alex.gronholm) * Date: 2020-10-17 09:23
>>> DummyDict = TypedDict('DummyDict', {'x': int, 'y': str}, total=False)
>>> DummyDict.__required_keys__
frozenset({'x', 'y'})

This happens because the TypedDict function does not pass the "total" metaclass argument to _TypedDictMeta() (instead passing "__total__" in the attribute namespace) and the new code that sets __required_keys__ and __optional_keys__ only checks the metaclass argument.
msg378819 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-10-17 15:08
Can you submit a PR to fix this? It looks like you already have a good understanding of the root cause of the problem, so it should be easy to fix. (Be sure to add a unit test.)

It can be backported to earlier Python versions that have typing.TypedDict (3.8+).
msg378820 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-10-17 15:09
Whoops, sorry, didn't see that you already have a PR. I'll review it next week during the core sprint.
History
Date User Action Args
2020-10-17 15:09:46gvanrossumsetmessages: + msg378820
2020-10-17 15:08:29gvanrossumsetmessages: + msg378819
2020-10-17 10:01:16xtreaksetnosy: + gvanrossum, levkivskyi
2020-10-17 09:39:24alex.gronholmsetkeywords: + patch
stage: patch review
pull_requests: + pull_request21699
2020-10-17 09:23:29alex.gronholmcreate