Am 25.02.10 18:08, schrieb Robert:
After (intended/controlled) reload or similar action on a module/class
the pickle/cPickle.dump raises errors like

pickle.PicklingError: Can't pickle <class 'somemodule.SomeClass'>: it's
not the same object as somemodule.SomeClass


Cause in pickle.py (and cPickle) is a line
"if klass is not obj:"

Shouldn't it be enough to have "if klass.__name__ != obj.__name__:" there?

No. This would alias classes of same name, but living in different modules.

So at least you need to compare these, too. I'm not sure if there aren't even more corner-cases. Python's import-mechanism can sometimes be rather foot-shoot-prone.

=> a bug report/feature request?

Classes can change face anyway during pickled state, why should a
over-pedantic reaction break things here during runtime?
(So far I'd need to walk the object tree in all facets and save against
inf loops like pickle himself and re-class things .. )

If anything it's a feature - and I doubt it's really needed. Because reloading pickles with intermittend reload-module-operations is to rare a case to be really supported IMHO.

Do yourself a favor, write a unit-test that tests the desired behavior that makes you alter your code & then reload. This makes the problem go away, and you have a more stable development through having more tests :)

Diez
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to