On 3/8/22 8:42 AM, Patrick Reader wrote:
I think the names `Required` and `NotRequired` are too generic for something which can only be used in one context (`TypedDict`s), and Could they be put into a pseudo-module like `typing.io`, e.g. `TypedDict.Required`?
It sounds like you are proposing something like: ``` from typing import TypedDict from typing.TypedDict import NotRequired # ๐ class Movie(TypedDict): title: str stars: NotRequired[int] ``` Is that really much different than: ``` from typing import NotRequired, TypedDict # ๐ class Movie(TypedDict): title: str stars: NotRequired[int] ``` Only the imports differ. And now users now have to specially remember that the "typing-related" NotRequired marker needs to imported not from `typing`, as is usual practice, but instead needs to be imported from somewhere else.
it is not immediately obvious when reading code without context what the difference between `NotRequired` and `Optional` might be.
Indeed PEP 655 ยง"How to Teach This" recommends not using both Optional and NotRequired in the same place, which might also mean the same file, and provides suggestions to avoid using Optional at all. Related: The word on the street is that "T|None" is likely to be a favored replacement for Optional in general going forward, since it's faster to type and doesn't require an extra import (of Optional from typing). Best, -- David Foster | Seattle, WA, USA Contributor to Python's type system