Hi!

I'd apreciate help with implementing pickling of classes with
metaclasses.

I have a class MyPolyRing, such that type(MyPolyRing) is some
metaclass that defines a __reduce__ method for MyPolyRing.

I thought that, generally, pickling should work for any object O
(where O might be a class) such that type(O).__reduce__(O) returns
data that can be pickled.

However, in my example (whith O=MyPolyRing), while
type(O).__reduce__(O) can be pickled and O can be reconstructed
"manually", pickling of O does not work:

  sage: f,L = type(MyPolyRing).__reduce__(MyPolyRing)
  sage: loads(dumps(type(MyPolyRing).__reduce__(MyPolyRing)))
  (Cached version of <built-in function _get_class_with_hash>, (<class
'_home_king_SAGE_work_fast_hash_fast_hash_pyx_0.FastHashAndDynamicMetaclass'>,
<class
'sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category'>))
  sage: loads(dumps(f))(*loads(dumps(L))) is MyPolyRing
  True
  sage: dumps(MyPolyRing)
  Traceback (most recent call last):
  ...
  PicklingError: Can't pickle <class
'sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category_with_hash'>:
attribute lookup
sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category_with_hash
failed

Hence, appparently I misunderstood the pickling protocol. What else is
to provide, on top of a __reduce__ method of the type of the object?
How can I find out what attribute is attempted to be looked up?

Best regards,
Simon

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to