Constructor Arguments

Skip to first unread message

Eoghan Murray

Jul 24, 2009, 3:43:46 PM7/24/09
to jsonpickle
On line 81 of
# fail gracefully if the constructor requires arguments

This took me ages to debug - perhaps it should just throw an error to
say that classes with mandatory arguments are unsupported.

Another strategy would be to feed in dummy attributes to the
constructor, as they are going to be overwritten by the pickled value
anyway... not sure if that wouldn't produce unexpected side effects


David Aguilar

Jul 25, 2009, 2:58:39 AM7/25/09


You must be using old-style Python classes.
You might find that things work much better with new-style
derived-from-object classes.

The problem with old-style classes and their constructors is
that there's no easy way to let jsonpickle know how to construct
it. We could support an extension mechanism wherein the
object returns the *args + **kwargs needed for class
construction. jsonpickle could save it and provide it at
object construction time..

I could imagine it being a __getdefault__(self) function that
classes would implement by doing return (args, kwargs) for use
by jsonpickle at object-construction time.
Let me know what you think.

Nonetheless, that's a lot of machinery when it might be simpler
to just use new-style classes.

Hopefully the code's under your control.

Anyways, the unpickler definitely needs a better error message
for the time being. Thanks for reporting it, I'll fix that.


Reply all
Reply to author
0 new messages