On 05/11/2026 8:29 PM EDT Rob Cliffe via Python-list
   <[1][email protected]> wrote:





   On 12/05/2026 00:39, Chris Angelico via Python-list wrote:

   On Tue, 12 May 2026 at 09:35, Chris Angelico <[2][email protected]>
   wrote:

   On Tue, 12 May 2026 at 09:06, Rob Cliffe via Python-list

   <[3][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

   betw

   Oh, and to clarify: both PEP 661 and the active docs at

   [4]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

   Well, I've read that doc and re-read the PEP, and AFAICS nowhere does
   it

   say clearly/explicitly

   that trying to create 2 sentinel objects with the same string will
   raise

   an Exception,

   nor what that Exception will be (which would be useful to know - I
   can't

   guess it).

   Assuming that this is the case, I think the doc should be clear about
   it.

   I guess you MIGHT infer it from reading between the lines (if you're

   smarter than me 🙂).

   Rob Cliffe



   --

   [5]https://mail.python.org/mailman3//lists/python-list.python.org

   You don't get the exception for creating two sentinels, you get the
   exception for pickling a sentinel whose __name__ string doesn't match
   the name was created into.



   From the documentation:



   [6]Pickling is supported for sentinel objects that are placed in the
   global scope of a module under a name matching the sentinel’s name, and
   for sentinels placed in class scopes with a name matching
   the [7]qualified name of the sentinel. Other sentinels, such as those
   defined in a function scope, are not picklable.

References

   1. mailto:[email protected]
   2. mailto:[email protected]
   3. mailto:[email protected]
   4. https://docs.python.org/3.15/library/functions.html#sentinel
   5. https://mail.python.org/mailman3//lists/python-list.python.org
   6. https://docs.python.org/3.15/library/pickle.html#module-pickle
   7. https://docs.python.org/3.15/glossary.html#term-qualified-name
-- 
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to