On Fri, Jun 7, 2013 at 1:54 PM, Mark Janssen <dreamingforw...@gmail.com> wrote: > On Fri, Jun 7, 2013 at 10:50 AM, Mark Janssen <dreamingforw...@gmail.com> > wrote: >>> >>> from pickle import dumps, loads >>> >>> Fruit.tomato is loads(dumps(Fruit.tomato)) >>> True >> >> Why are you using is here instead of ==? You're making a circular >> loop using "is" > > I should add that when you're serializing with pickle and then > reloading, the objects should be seen as "essentially equivalent". > This means that they are either byte-by-byte equivalent (not sure > actually if Python actually guarantees this), or every element would > still compare equal and that is what matters.
For global objects such as functions and classes -- and singletons such as None, Ellipsis, True, and False -- pickling and unpickling is actually supposed to retain the "is" relationship as well. I don't know if enums *actually* preserve this invariant, but my default expectation of the One Obvious Way would be that enums, being uniquely-named objects that know their name and container, should be considered global objects in the same fashion as classes and functions, *and* that as singletons, they'd also be treated in the same way as None, Ellipsis, etc. That is, there are two independent precedents for objects like that preserving "is" upon pickling and unpickling. (As another precedent, my own SymbolType library (available on PyPI) preserves the "is"-ness of its named symbol objects upon pickling and unpickling.) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com