Default Value

Tim Chase python.list at tim.thechases.com
Thu Jun 20 22:02:07 EDT 2013


On 2013-06-20 21:40, Roy Smith wrote:
> In article <mailman.3647.1371777895.3114.python-list at python.org>,
>  Tim Chase <python.list at tim.thechases.com> wrote:
> 
> > On 2013-06-21 01:08, Steven D'Aprano wrote:
> > > Here's my syntax plucked out of thin air:
> > > 
> > > def func(arg, x=expression, !y=expression):
> > >     ...
> > > 
> > > where y=expression is late-bound, and the above is compiled to:
> > > 
> > > def func(arg, x=expression, y=None):
> > >     if y is None:
> > >         y = expression
> > >     ...
> > 
> > I think it would have to translate to something like
> > 
> >   _temp_semaphore = object()
> >   def func(arg, x=expression, y=_temp_semaphore):
> >     if y is _temp_semaphore:
> >       y = expression
> > 
> >     ...
> 
> You can go around and around on that one.  Whatever distinguished
> value you set aside to mean "no argument passed", somebody will
> come up with a use case for why they might want to pass that as a
> real value.

That's why I suggested using an "is" test against a custom/local(ish)
semaphore instance that is only used for the particular invocation in
which the "def" statement occurs.

-tkc







More information about the Python-list mailing list