[Python-ideas] PEP 505 (None coalescing operators) thoughts

Random832 random832 at fastmail.com
Thu Oct 1 23:12:26 CEST 2015


On Thu, Oct 1, 2015, at 16:57, Ron Adam wrote:
> And to go out on a limb... ;-)
> 
> Another possibility is to have a *special magic callable* that when 
> called skips the argument evaluation and returns None.

That's dangerous talk indeed. Special magic callables are Lisp
territory. ;)

And I don't even know how you'd implement it efficiently without them
being known at compile-time.

I guess at *every* callsite you could test if the callable is magic, and
if it is evaluate the arguments, and if it's not just pass in a lambda
that will return the arguments. But you've got to generate those lambdas
for *all* callsites, even the vast majority that will never be a magic
callable.

What if the callable only wants *some* of the arguments? Hey, if this
had existed back then the ternary operator could have been a normal
function - instead of (b() if a else c()) just do iif(a, b(), c()).

And is this going to be fully general? I.e. should this be supported for
regular operators? If __add__ is magic does + do this, for example?


More information about the Python-ideas mailing list