This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author taleinat
Recipients iritkatriel, taleinat
Date 2021-05-13.13:17:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1620911826.39.0.0347354211372.issue44123@roundup.psfhosted.org>
In-reply-to
Content
I recently noticed that some functions use sentinel values to differentiate between not having been passed any value vs. None. One example of this is traceback.print_exception(), hence I'm adding Irit to the nosy list.

However, using e.g. `sentinel = object()` or a single instance of a dedicated class/type can break when combined with pickling (see examples below).

Since these sentinel are usually compared using the `is` operator, having more than a single instance will break things, sometimes in very confusing ways.

I suggest ensuring that a single instance is always used, probably by using a class with a __new__() method making sure to always return a single instance.


>>> sentinel = object()
>>> sentinel2 = pickle.loads(pickle.dumps(sentinel))
>>> sentinel is sentinel2
False
>>> sentinel
<object object at 0x7fd00a986560>
>>> sentinel2
<object object at 0x7fd00a986500>


>>> class A:
...     pass
...     
>>> a = A()
>>> a2 = pickle.loads(pickle.dumps(a))
>>> a is a2
False
>>> a
<__main__.A object at 0x7fd00a9972f0>
>>> a2
<__main__.A object at 0x7fd009599450>
History
Date User Action Args
2021-05-13 13:17:06taleinatsetrecipients: + taleinat, iritkatriel
2021-05-13 13:17:06taleinatsetmessageid: <1620911826.39.0.0347354211372.issue44123@roundup.psfhosted.org>
2021-05-13 13:17:06taleinatlinkissue44123 messages
2021-05-13 13:17:06taleinatcreate