[Erp5-dev] Default parameter (list) [eg] in OrderBuilder - which way is better?
Łukasz Nowak
lukasz.nowak at ventis.com.pl
Thu Jun 12 10:59:30 CEST 2008
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.)
But ok. So the error, is that those variables wasn't changed to list if
None was passed?
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.
More information about the Erp5-dev
mailing list