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
Best wishes
Rob Cliffe
On 11/05/2026 08:13, Jon Ribbens via Python-list wrote:
On 2026-05-11, Lawrence D’Oliveiro<[email protected]> wrote:
On Sun, 10 May 2026 21:01:00 -0700, Paul Rubin wrote:
Lawrence D’Oliveiro<[email protected]> 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.
--
https://mail.python.org/mailman3//lists/python-list.python.org