
The scenario I'm thinking about is like this: (base) 84-tmp % python Python 3.9.1 (default, Dec 11 2020, 14:32:07) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information.
import pickle cheap_sentinel = object() id(cheap_sentinel) 140469343429632 pickle.dump(cheap_sentinel, open('sentinel.pkl', 'wb'))
(base) 85-tmp % python Python 3.9.1 (default, Dec 11 2020, 14:32:07) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information.
import pickle cheap_sentinel = object() id(cheap_sentinel) 139852505814016 id(pickle.load(open('sentinel.pkl', 'rb'))) 139852505813968
It would be pleasant if there were a way to make "cheap_sentinel" be the same thing—either by equality or by identity—betweeen those two runs of the interpreter. None or Ellipsis have that property, of course. So do, for example, integers, at least by equality if not identity (yes, of course, we might get identity by interning, but it's not guaranteed). On Thu, May 20, 2021 at 3:10 PM Ethan Furman <ethan@stoneleaf.us> wrote:
On 5/20/21 10:47 AM, David Mertz wrote:
On Thu, May 20, 2021 at 6:21 AM Tal Einat wrote:
I think it's worth preserving the idiom of comparing sentinels using `is`, as we do for `None` and other existing sentinel values. It's relatively easy to do, such as by using a single-value Enum or by using a class with a custom __new__.
This only works if:
a) Unpickling is within a single interpreter session
I don't understand. If I pickle a sentinel in session A, then unpickle it in session B, why wouldn't I get the "same" sentinel?
b) Sentinels are explicitly created in imported modules, not as a runtime, user-level creation
Why would you ever have a sentinel not always created?
Hoping-to-learn-something-new'ly yrs,
-- ~Ethan~ _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/OLTV44EV... Code of Conduct: http://python.org/psf/codeofconduct/
-- The dead increasingly dominate and strangle both the living and the not-yet born. Vampiric capital and undead corporate persons abuse the lives and control the thoughts of homo faber. Ideas, once born, become abortifacients against new conceptions.