On Wed, 1 Dec 2021 at 15:24, David Mertz, Ph.D. <david.me...@gmail.com> wrote: > > On Wed, Dec 1, 2021 at 9:24 AM Paul Moore <p.f.mo...@gmail.com> wrote: >> >> I think that the only >> thing I might use it for is to make it easier to annotate defaults (as >> f(a: list[int] => []) rather than as f(a: list[int] | None = None). > > > Why not `f(a: Optional[list[int]] = None)`? > > I'm not counting characters, but that form seems to express the intention > better than either of the others IMHO.
If None were a valid argument, and I was using an opaque sentinel, Optional doesn't work, and exposing the type of the sentinel is not what I intend (as it's invalid to explicitly supply the sentinel value). Also, Optional[list[int]] doesn't express the intent accurately - the intended use is that people must supply a list[int] or not supply the argument *at all*. Optional allows them to supply None as well. As I say, I don't consider this an intended use case for the feature, because what I'm actually discussing here is optional arguments and sentinels, which is a completely different feature. All I'm saying is that the only case when I can imagine using this feature is for when I want a genuinely opaque way of behaving differently if the caller omitted an argument (and using None or a sentinel has been good enough all these years, so it's not exactly a pressing need). Let's just go back to the basic point, which is that I can't think of a realistic case where I'd want to actually use the new feature. Paul _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/NYHE57O3JVD4GWBIJC57MB5E7PWG6YPR/ Code of Conduct: http://python.org/psf/codeofconduct/