• Coming In Python 3.15: Sentinel Values

    From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.python on Mon May 11 00:17:36 2026
    From Newsgroup: comp.lang.python

    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.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Paul Rubin@no.email@nospam.invalid to comp.lang.python on Sun May 10 21:01:00 2026
    From Newsgroup: comp.lang.python

    Lawrence D’Oliveiro <ldo@nz.invalid> writes:
    For those times when a simple “None” marker element is not sufficient, this will be very convenient.

    object() has always worked for me.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.python on Mon May 11 06:24:32 2026
    From Newsgroup: comp.lang.python

    On Sun, 10 May 2026 21:01:00 -0700, Paul Rubin wrote:

    Lawrence D’Oliveiro <ldo@nz.invalid> writes:

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

    object() has always worked for me.

    I have done the same, on a few occasions. That’s been a common idiom
    among Python programmers since practically forever. The PEP discusses
    why this is less than an optimal solution: less-than-explanatory
    diagnostics, and difficulty with type signatures for static typing.
    Also, an “is” comparison fails if you should (inadvertently or
    otherwise) make a copy of your sentinel object.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Jon Ribbens@jon+usenet@unequivocal.eu to comp.lang.python on Mon May 11 07:13:10 2026
    From Newsgroup: comp.lang.python

    On 2026-05-11, Lawrence D’Oliveiro <ldo@nz.invalid> wrote:
    On Sun, 10 May 2026 21:01:00 -0700, Paul Rubin wrote:
    Lawrence D’Oliveiro <ldo@nz.invalid> writes:
    For those times when a simple “None” marker element is not
    sufficient, this will be very convenient.

    object() has always worked for me.

    I have done the same, on a few occasions. That’s been a common idiom
    among Python programmers since practically forever. The PEP discusses
    why this is less than an optimal solution: less-than-explanatory
    diagnostics, and difficulty with type signatures for static typing.

    I've always used (and seen) "SENTINEL = []"...

    Also, an “is” comparison fails if you should (inadvertently or
    otherwise) make a copy of your sentinel object.

    That doesn't seem terribly likely to happen by accident though.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Tim Daneliuk@info@tundraware.com to comp.lang.python on Mon May 11 19:51:21 2026
    From Newsgroup: comp.lang.python

    On 5/10/26 19:17, Lawrence D’Oliveiro wrote:
    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. <SNIP>

    Forgive me, but this smells of Feeping Creaturism to solve a not very important question
    at the expense crufting up the language and decreasing clarity.

    I have seen this happen with every single language I ever used except perhaps, assembler, C, and Forth.

    Oh well, there's an opportunity here for someone to excise the noisy PEPs and create Python Lite.


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.lang.python on Tue May 12 02:42:01 2026
    From Newsgroup: comp.lang.python

    On Mon, 11 May 2026 19:51:21 -0500, Tim Daneliuk wrote:

    On 5/10/26 19:17, Lawrence D’Oliveiro wrote:

    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.

    Forgive me, but this smells of Feeping Creaturism to solve a not
    very important question at the expense crufting up the language and decreasing clarity.

    In order to be forgiven, you will have to explain why you think so.
    Some of us have done enough Python programming that we can see the
    utility of such a feature, minor as it is.
    --- Synchronet 3.22a-Linux NewsLink 1.2