Re: PEP 505 (None-aware operators) for Python 3.11
Petr Viktorin <[email protected]> Tue, 20 Sep 2022 10:59:51 +0200
| Newsgroups | gmane.comp.python.devel |
|---|---|
| Message-ID | <[email protected]> |
On 19. 09. 22 17:58, Guido van Rossum wrote: > Personally I think returning None is a fine API design, and IMO the > concerns about this pattern are overblown. Note that X|None is no > different than the "Maybe X" pattern that functional programmers are so > fond of. I must disagree here. With `X|None` there is no way to do `Maybe[Maybe[X]]`, and FP is all about proper composition. One practical consequence is that "Maybe X" doesn't have the problem that PEP 661 (Sentinel Values) tries to solve. > On Mon, Sep 19, 2022 at 8:02 AM Philipp Burch <[email protected] > <mailto:[email protected]>> wrote: > > Hi all, > > I've only here found out that there is a discussion going on about > those > none-aware operators and my first thought was "great, finally!". FWIW, > I'd be happy with the syntax suggestion in the PEP, since '?' looks > rather intuitive to me to mean something like "maybe". > > However, I then read the mentioned post of Steve Dower, with the final > summary: > > > So to summarise my core concern - allowing an API designer to "just > use None" is a cop out, and it lets people write lazy/bad APIs rather > than coming up with good ones. > > This is a very good point. In fact, I've never really thought about it > that way and of course he's totally right that "SomeType | None" (or > Optional[SomeType], which also somehow made me feel that this usage is > fairly intended) is not optimal, at least for user defined > types/classes. The problem is, that I never actually thought about his > suggested way. And I wouldn't be surprised if this holds for many other > people as well. > > Maybe it would be great to boldly mention these thoughts in the > documentation at an appropriate place. In my opinion, there are at > least > the following good places where this would fit nicely: > > - The documentation of the dataclasses > (https://docs.python.org/3/library/dataclasses.html > <https://docs.python.org/3/library/dataclasses.html>), since this is > probably the most common use case for the "| None" pattern. Going > further, the dataclasses functionality might even be extended to > make it > simpler to generate such null-types (or however they are called), so > that it is no longer "a tonne more work". > > - Linters like pylint could emit a note when seeing the "| None" > pattern, linking to the explanation about why it is possibly not the > best way to do it. > > - The documentation of the discussed None-aware operators. Since these > new operators are closely coupled to the arguably suboptimal "| None" > pattern, it is probably good to tell folks right there why they should > consider better alternatives. > > As mentioned, I absolutely see Steve's point. However, there are many > Python scripts/programs working without a complex API, where this "| > None" pattern may still have its legitimate uses and the none-aware > operators can make code easier to read (and write). > > Best regards, > Philipp > _______________________________________________ > Python-Dev mailing list -- [email protected] > <mailto:[email protected]> > To unsubscribe send an email to [email protected] > <mailto:[email protected]> > https://mail.python.org/mailman3/lists/python-dev.python.org/ > <https://mail.python.org/mailman3/lists/python-dev.python.org/> > Message archived at > https://mail.python.org/archives/list/[email protected]/message/Q2MOF5CJ7LSSZMEMB43YVEXD6PFATYTA/ <https://mail.python.org/archives/list/[email protected]/message/Q2MOF5CJ7LSSZMEMB43YVEXD6PFATYTA/> > Code of Conduct: http://python.org/psf/codeofconduct/ > <http://python.org/psf/codeofconduct/> > > > > -- > --Guido van Rossum (python.org/~guido <http://python.org/~guido>) > /Pronouns: he/him //(why is my pronoun here?)/ > <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/> > > _______________________________________________ > Python-Dev mailing list -- [email protected] > To unsubscribe send an email to [email protected] > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at https://mail.python.org/archives/list/[email protected]/message/7HEZXSLT2A63RDLXTJAOQWGBHNU3WDCR/ > Code of Conduct: http://python.org/psf/codeofconduct/ _______________________________________________ Python-Dev mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/MB6DFTH3CEDKP45YELP4GZ7R7LZSPTZ2/ Code of Conduct: http://python.org/psf/codeofconduct/