On 19 July 2018 at 13:30, Jonathan Fine <[email protected]> wrote: > Hi > >> There is a formatted version of this PEP at >> https://www.python.org/dev/peps/pep-0505/ > > I've taken a look at this, and have some comments on the first two > examples drawn from standard library code. (And a very grateful +10 > for writing a script to find such examples.) > > I've started a subthread, just to discuss the ?= and ?? operators. And > something newish, that I call OR. > > FIRST EXAMPLE > The first example is > --- > From bisect.py: > def insort_right(a, x, lo=0, hi=None): > # ... > if hi is None: > hi = len(a) > --- > > Here, None is a sentinel value. The simpler code > --- > hi = hi or len(a) > --- > fails when hi is zero (or any other value that is False in the boolean > context). > > This can be fixed by introducing a new operator OR which is similar to > 'or' but has the semantics this example requires. Thus, given OR we > can write > --- > hi = hi OR len(a) > --- > where (A OR B) returns A if A is not None, otherwise it returns B. > > (Recall that (A or B) returns A if bool(A), otherwise it returns B.)
How does (A OR B) differ from the PEP's (A ?? B)? I don't particularly like it in either form. But ?? at least has the advantage of being used in other languages. [...] > Comments ?? suggestions. For example, would a None-aware AND operator be > useful? I see no value in a None-aware AND. Real use cases are the only reasonable argument for such a thing, not arguments based on symmetry (or generalisation). And I doubt I'd find real-world use cases particularly compelling. Paul _______________________________________________ Python-ideas mailing list [email protected] https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
