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

Brian O'Neill twangist at gmail.com
Tue Sep 29 20:33:36 CEST 2015

> > A further virtue of 
> > 
> >     self.vertices = vertices or []
> > 
> > and the like is that they coerce falsy parameters of the wrong type to the falsy object of the correct type.
> > E.g. if vertices is '' or 0, self.vertices will be set to [], whereas the ternary expression only tests 
> > 
> > for not-None so self.vertices will be set to a probably crazy value.
> Doesn't seem like a virtue to me, seems like it's probably hiding a bug
> in the calling code, which may have other ramifications. Better to have
> the "crazy value" visible and fail faster, so you can go fix that bug.
> Carl
I have to agree. It isn't a "virtue", and it's best not to mask such mistakes. But it *is* a... property of the shorter construct that it's more forgiving, and doesn't have the same semantics.
PS -- My first post, and I lost the "Re:" in the Subject, hence this orphan thread which I'm content to see go no further.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150929/4de18530/attachment.html>

More information about the Python-ideas mailing list