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
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/ZEO56ZSUVWHOPGN4MASUNVHBOHBINBG3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to