Re: Coming In Python 3.15: Sentinel Values

Chris Angelico via Python-list <[email protected]> Tue, 12 May 2026 09:39:03 +1000
Newsgroups gmane.comp.python.general
Message-ID <CAPTjJmovNgbuxhJ0ic6uUs=PY=opkoD2xRtHsfHjD+hHub=U-A@mail.gmail.com>
On Tue, 12 May 2026 at 09:35, Chris Angelico <[email protected]> wrote:
>
> 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

Oh, and to clarify: both PEP 661 and the active docs at
https://docs.python.org/3.15/library/functions.html#sentinel do
describe the behaviour of pickling, defining exactly why you can't get
the confusion you're describing.

ChrisA