Default Value

Tim Chase python.list at tim.thechases.com
Thu Jun 20 21:26:34 EDT 2013


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

    ...

because there are times you want to be able to pass None as a legit
value in such a case (speaking from the trenches after getting stung
by exactly that case on multiple occasions).

-tkc





More information about the Python-list mailing list