+ // Nested class workaround
+ // With the python code below::
+ // class A:
+ // class B:
+ // pass
+ // Python 2.6 erroneously set the B.__name__ to "B" instead of "A.B".
+
+ // Furthermore, upon pickling (here in save_global)
+ // *and* unpickling (in load_global) a class
+ // with name "A.B" in a module mod, the standard
+ // cPickle module searches for "A.B" in mod.__dict__
+ // instead of looking up "A" and then "B" in the result.
+ //
+ // The code below makes a library callback to a
+ // function that searches recursively for B in the
+ // classes and nested classes of mod, set the name for
+ // B to its appropriate value A.B, and inserts A.B in
+ // mod.__dict__ (a hack).
+ //
+ // This library callback will only occur upon the
+ // first time the class A.B is pickled, so the
+ // overhead is negligible, and this code was much
+ // easier to write in plain python.
+ //
+ // Todo:
+ // - Fix Python, and cPickle
+ // - In the mean time, have some Python - C API expert
+ // rewrite the callback below
Partager