[Python-ideas] Add new `Symbol` type

Chris Angelico rosuav at gmail.com
Tue Jul 10 17:18:01 EDT 2018


On Wed, Jul 11, 2018 at 6:53 AM, Barry Warsaw <barry at python.org> wrote:
> Guido van Rossum wrote on 7/6/18 08:31:
>>
>> Thanks for an interesting discussion. I would also urge people to limit
>> the
>> use of such sentinels for cases where it is *really* important to
>> distinguish between, say, f(None) and f(). In most cases using def
>> f(arg=None) is fine, and often it is even a virtue that passing None or
>> omitting an argument has exactly the same meaning. (I do know there a
>> cases
>> where this doesn't apply -- I just think they ought to be fairly unusual.)
>
>
> One of the most common places I use a non-None sentinel is when None is a
> valid value in a dictionary:
>
> _missing = object()
>
> if mydict.get('foo', _missing) is _missing:
>      # it ain't there
>
> I generally don't feel like a more complicated repr is valuable here, so I
> haven't really wanted a built-in sentinel in a long time.  My search fu is
> weak today, but I'm pretty sure I suggested such a thing (and was rightly
> persuaded against it) many years ago.

For that specific example, I would just use:

try: mydict['foo']
except KeyError:
    # it ain't there

ChrisA


More information about the Python-ideas mailing list