Re: Coming In Python 3.15: Sentinel Values

Chris Angelico via Python-list <[email protected]> Tue, 12 May 2026 09:35:57 +1000
Newsgroups gmane.comp.python.general
Message-ID <CAPTjJmoNi=7_2YUHcEMNxC5sZVT0hi4=tGccGR2FjiPeEkzfRA@mail.gmail.com>
On Tue, 12 May 2026 at 09:06, Rob Cliffe via Python-list
<[email protected]> wrote:
>
> I've read PEP 661 and I have a question - can anybody answer it?
> The PEP makes clear that any call to sentinel() will return a fresh
> sentinel object - even if it is called twice with the same string parameter.
> It states that sentinel objects have two public attributes: __name__ and
> __module__.
> It also states that pickling and unpickling a sentinel will return the
> same object:
> MISSING = sentinel('MISSING')
> assert pickle.loads(pickle.dumps(MISSING)) is MISSING
>
> So if I write (in the same module, in the global scope):
>
> somename = 'MISSING'
> MISSING1 = sentinel(somename)
> MISSING2 = sentinel(somename)
> assert MISSING2 is not MISSING1
> LAZARUS1 = pickle.loads(pickle.dumps(MISSING1))
> LAZARUS2 = pickle.loads(pickle.dumps(MISSING2))
>
> how does Python know that
>      LAZARUS1 is MISSING1
>      LAZARUS2 is MISSING2 is not MISSING1

Try it and you'll see! You won't get that far; it'll raise an exception.

ChrisA