Re: Marking individual TypedDict items as required
I’m glad this is being taken up and the PEP looks good to me. I second the idea of adding NotRequired (Or NonRequired) as well, as I’m glad this is being taken up and the PEP looks good to me. I second the idea of adding NotRequired (Or NonRequired) as well, as personally I have seen more cases of dicts where there are many required keys and few non-required ones (was going to say “optional” :). Use of required keys when possible provides a more precise type, so I would prefer to only single out the non-required keys to avoid (if we only had Required) accidentally having other keys being non-required because I forgot to specify that. In other words, I’d like to make it take more effort to make keys non-required (but not so much so that I feel that the current situation with subclassing and flipping the total parameter is ideal). TypeScript’s :? syntax is essentially doing the same thing as NotRequired would, by making it (albeit very slightly) more work to define a non-required key.
participants (1)
-
syastrov@gmail.com