On Thu, Feb 11, 2021 at 22:05 David Foster
On 2/11/21 9:51 PM, Guido van Rossum wrote:
On Thu, Feb 11, 2021 at 9:13 PM Paul Bryan
mailto:pbryan@anode.ca> wrote: 1. I understand your rationale for not using Optional; however, I am concerned about the potential for confusion in a world where there is both an Optional[...] and Required[...] type hint. Also, the potential for an ugly (but valid?!) Required[Optional[...]] construct. To reduce confusion we can recommend T|None over Optional[T].
I do in fact make that recommendation for Python 3.10. See §"How to Teach This".
But I also have a related open issue in §"Open Issues" that ponders what can be done in Python 3.9 and lower, where the T|None syntax isn't available. Maybe:
Yes (Python 3.5 - 3.9): Required[Union[..., None]]
Avoid: Required[Optional[...]]
I think that’s too complex. And note that there’s no reason a type checker couldn’t support T|None in all Python versions that support ‘from __future__ import annotations’. I also expect the case will occur rarely.
-- --Guido (mobile)