On 1/18/21 9:19 AM, Eric Traut wrote:
> I don't think it's feasible to deprecate `Optional[x]`. It's too
ubiquitous. However, I predict that it its use will fade over time in
favor of `x | None` as specified in [PEP
604](https://www.python.org/dev/peps/pep-0604/).
On 1/18/21 12:55 PM, Guido van Rossum wrote:
> The syntax x? is quite controversial and unlikely to be accepted anytime
> soon (and requires parser changes so invites much more scrutiny).
Points taken. I'll restate my last argument using this new information:
Let's say we use the form Required[...] only on total=False TypedDict
definitions. You could encounter code like:
class MyTypedDict(TypedDict, total=False):
foo: Required[str]
bar: Required[int|None]
baz: float|None
qed: bool
This code seems fairly straightforward to me. So long as we discourage
in documentation the use of Optional[...] in the presence of
Required[...] -- perhaps explicitly in favor of the `T|None` form -- it
looks to me like Required[...] would be readable even in a more complex
(real-world) case like this definition shows.
Any major objections to the Required[...] syntax (in combination with
total=False) being the solution to defining the optionality/requiredness
of individual fields on TypedDicts? I'm feeling like the discussion and
decisions so far are ripe to make into an actual PEP.
--
David Foster | Seattle, WA, USA
Contributor to TypedDict support for mypy