[Erp5-dev] Default parameter (list) [eg] in OrderBuilder - which way is better?

Mikolaj Antoszkiewicz mikolaj at erp5.pl
Thu Jun 12 11:35:13 CEST 2008



Łukasz Nowak wrote:
> Hello,
> 
> On 2008-06-12, 10:54:18
> Mikolaj Antoszkiewicz <mikolaj at erp5.pl> wrote:
> 
>>
>> Łukasz Nowak wrote:
>>> Hello,
>>>
>>> If list is passed as optional argument, its defaults shall be None
>>> or []?
>>>
>>> Take for example ERP5/Document/OrderBuilder.py - everywhere
>>> foo_list on method argument list has defaults to None. Without
>>> proper initialisation there are problems, if method is called
>>> without changing parameter to empty list eg.
>>>
>>> Which is more correct:
>>>
>>> def funA(self, movement_list=None):
>>>   if movement_list is None:
>>>     movement_list = []
>>>   =snip=
>>>
>>> def funB(self, movement_list=[]):
>>>   =snip=
>>>
>>> ?
>>>
>> In general, it's not desirable to use unmutables as default
>> parameters. They behave differently than usually expected to
>> (consequent calls to that function will work on existing list, not on
>> a new empty one as one might expect)
>> That's why funB type should be used only if You know what You're
>> doing and You want that.
> 
> unmutable is immutable? list ([]) is not immutable, isn't it? So this
> is not that issue? Or I got something wrong? (Now I'm quite confused.)
> 
Arghh, sorry, sorry, my bad! Of course I meant MUTABLES and list is of 
course mutable.

Mikolaj

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3229 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20080612/cbd72dee/attachment.bin>


More information about the Erp5-dev mailing list