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

Łukasz Nowak lukasz.nowak at ventis.com.pl
Wed Jun 11 09:27:17 CEST 2008


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=

?

As I'm not passing movement_list to callAfterBuildingScript in
OrderBuilder (we are ongoing transition from 15401), this method dies
with exception.

Attached patch using funB method, only method declarations.

funA method allows caller to pass wrong argument type (None) while
invoking funA. Is it ok to do it without any warning?

Regards,
Luke

-- 
Łukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...'' I am only craftsman.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OrderBuilder.py-change-default-parameters.patch
Type: text/x-patch
Size: 1669 bytes
Desc: not available
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20080611/a939023f/attachment.bin>


More information about the Erp5-dev mailing list