Since the subject is this,
I will note that past week, I resorted twice to create an Enum with a single element,
and then alias the element on the module namespace, so that it would work
as a "polished" sentinel.


import enum

class Whatever(enum.Enum):
     EMPTY = "EMPTY"

EMPTY = Whatever.EMPTY

A "repeat yourself three times" - certainly not that nice. 
But its use was a bit off the ones listed here in a sense these
are meant to be explicitly passed to some methods (rather, 
placed inside data structures) to indicate a desired behavior.

On Fri, 14 May 2021 at 21:03, Nick Coghlan <> wrote:
On Sat, 15 May 2021, 5:39 am Tal Einat, <> wrote:

(snip useful feature summary)

The common `SENTINEL = object()` idiom fails #3, #4 and #5. This is
what I've been using for years, and I now think that it isn't good
enough. This not having a nice repr is what started this thread.

I'd also personally prefer something simple, ideally without a new
class or module.

The key advantage of a new base class is that it offers a way to communicate a shift in the recommended development idiom. "sentinel = object()" is entrenched enough that I would expect that only a "types.Sentinel" base class would stand a good chance of displacing it.

Why the "types" module? I don't think this is important enough to be a builtin type, and the types module is cheap to import, doesn't bring in many transitive dependencies, and the purpose of the new base class would be defining custom sentinel types with various desirable properties.


Python-Dev mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct: