Re: Sentinel values for special cases

2006-10-27 Thread Gabriel Genellina
At Friday 27/10/2006 21:09, Ben Finney wrote: > > >GLOBAL = object() > > > > > >def insert_ids(ids=GLOBAL): > > >if ids is GLOBAL: > > >ids = get_global_ids() > > > >The one disadvantage of this approach is that it complicates > >pickling if/when you store the stentin

Re: Sentinel values for special cases

2006-10-27 Thread Ben Finney
Gabriel Genellina <[EMAIL PROTECTED]> writes: > At Friday 27/10/2006 11:40, Aahz wrote: > > Ben Finney wrote: > > >GLOBAL = object() > > > > > >def insert_ids(ids=GLOBAL): > > >if ids is GLOBAL: > > >ids = get_global_ids() > > > >The one disadvantage of this approach is

Re: Sentinel values for special cases

2006-10-27 Thread Ben Finney
[EMAIL PROTECTED] (Aahz) writes: > Ben Finney <[EMAIL PROTECTED]> wrote: > >Use a unique do-nothing object, defined at the module level so > >callers can easily get at it [...] > > > >GLOBAL = object() > > > >def insert_ids(ids=GLOBAL): > >if ids is GLOBAL: > >ids = ge

Re: Sentinel values for special cases

2006-10-27 Thread Gabriel Genellina
At Friday 27/10/2006 11:40, Aahz wrote: >GLOBAL = object() > >def insert_ids(ids=GLOBAL): >if ids is GLOBAL: >ids = get_global_ids() The one disadvantage of this approach is that it complicates pickling if/when you store the stentinel in an instance. There are ways

Re: Sentinel values for special cases

2006-10-27 Thread Aahz
In article <[EMAIL PROTECTED]>, Ben Finney <[EMAIL PROTECTED]> wrote: > >Fourth, if you have decided that a magic sentinel value is called for >but None is already taken for some other purpose, don't use a >string. Use a unique do-nothing object, defined at the module level so >callers can easily

Re: Sentinel values for special cases

2006-10-26 Thread Ben Finney
"Paddy" <[EMAIL PROTECTED]> writes: > None is what Python readers would expect as a sentinel value, but if > any of your data fields could have None as a valid value then you may > have to switch to a module level constant. > Be wary of using sentinel values which are strings, if your data could >

Re: Sentinel values for special cases

2006-10-26 Thread Paddy
Ben Finney wrote: > Howdy all, > > Ned Batchelder blogged[0] about a debate over checking function > parameters, and to what extent dynamic typing should be relied upon. > > I was one of many who commented, but I wrote what purports to be a > comprehensive checklist when considering special-case in

Sentinel values for special cases

2006-10-26 Thread Ben Finney
Howdy all, Ned Batchelder blogged[0] about a debate over checking function parameters, and to what extent dynamic typing should be relied upon. I was one of many who commented, but I wrote what purports to be a comprehensive checklist when considering special-case inputs for functions. I thought