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

Sven R. Kunze srkunze at mail.de
Tue Sep 29 19:30:21 CEST 2015


On 29.09.2015 18:58, Emile van Sebille wrote:
> On 9/29/2015 9:20 AM, Rob Cliffe wrote:
>> Why not
>>
>> def __init__(self, vertices=None, edges=None, weights=None,
>> source_nodes=None):
>>      self.vertices     = vertices     if vertices     is not None 
>> else []
>>      self.edges        = edges        if edges        is not None 
>> else []
>>      self.weights      = weights      if weights      is not None 
>> else {}
>>      self.source_nodes = source_nodes if source_nodes is not None 
>> else []
>
> I don't understand why not:
>
>       self.vertices     = vertices     or []
>       self.edges        = edges        or []
>       self.weights      = weights      or {}
>       self.source_nodes = source_nodes or []

People fear that when you pass some special objects into the constructor 
that behaves like False, this special object is replaced by [] or {}.

I for one don't think it's a real issue. However, it has been said that 
people got bitten by this in the past. I don't know what the heck they 
did, but I presume they tried something really really nasty.

Best,
Sven


More information about the Python-ideas mailing list