[issue20804] Sentinels identity lost when pickled (unittest.mock)

R. David Murray report at bugs.python.org
Fri Feb 28 23:39:37 CET 2014


R. David Murray added the comment:

Yes, exactly, you don't use is for equality comparison.  It tests object identity, which is why it makes sense to use it with a sentinel.

The 'name' of the sentinel is purely a way to store and retrieve particular sentinel objects.  The sentinel itself does not have a name.

Good point about copy...the copy protocol and the pickle protocol are closely related, so preventing a sentinel from being pickled may prevent it from being copied as well.  It is an interesting question how surprising people will find it for a sentinel to throw an error if an attempt is made to copy it, but if the test is using a sentinel, presumably it expects the sentinel to survive unchanged, so an error on copy is probably a reasonable result.  You could imagine someone wanting to use a sentinel to test that copy happens by making sure they get back a different object, though, so it is not entirely clear cut.  However, I expect that to be *much* less common than wanting to use it to prove that an object is preserved (not copied).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20804>
_______________________________________


More information about the Python-bugs-list mailing list