Coming In Python 3.15: Sentinel Values

Lawrence D’Oliveiro <[email protected]> Mon, 11 May 2026 00:17:36 -0000 (UTC)
Newsgroups comp.lang.python
Organization A noiseless patient Spider
Message-ID <[email protected]>
A new feature coming in Python 3.15 is the “sentinel” class, useful
for creating custom values to mark the end of sequences of items, that
kind of thing
<https://docs.python.org/3.15/library/functions.html#sentinel>,
<https://peps.python.org/pep-0661/>.

For those times when a simple “None” marker element is not sufficient,
this will be very convenient.

However, one limitation is that you cannot subclass the “sentinel”
class. I wonder why not? Consider this behaviour, from the PEP:

    Sentinel objects are “truthy”, i.e. boolean evaluation will result
    in True. This parallels the default for arbitrary classes, as well
    as the boolean value of Ellipsis. This is unlike None, which is
    “falsy”.

Suppose you want a sentinel to be “falsy”? The obvious way would be to
subclass it and override the __bool__ method accordingly. But this is
not allowed. The PEP goes into a lot of detail about the design
rationale in other areas, but not this one.