[Python-ideas] __missing__ object/keyword

Terry Reedy tjreedy at udel.edu
Sat Nov 8 21:05:36 CET 2008

Jim Jewett wrote:
> On Thu, Nov 6, 2008 at 3:31 PM, George Sakkis <george.sakkis at gmail.com> wrote:
>> Several times I find myself using the following idiom:
>> _Missing = object()   # sentinel
>> def foo(x, y=_Missing):
>>   if y is _Missing:
>>     do_this
>>   else:
>>     do_that
> And I often catch myself trying to write
>     def foo(x, y=object()):
>         if y is ... # oops, I need to define the y *outside* the function.

if type(y) is object: ...

And no, there is no problem if a foolish caller passes an object(), 
because such has no meaning other than what your sentinal y means.

More information about the Python-ideas mailing list