serializing instance variables pointing to other functions #77

Closed
kylebgorman opened this Issue Aug 16, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@kylebgorman

When serializing a class instance which has an instance variable pointing to a function (from outside of that class), said instance variable is silently deleted. Minimal example:

def hello_world():
    print "Hello, world!"


class Foo(object):

    def __init__(self, hello_fnc=hello_world):
         self.hello_fnc = hello_fnc

    def hello(self):
        self.hello_fnc()

bar = Foo()
bar.hello() # "Hello, world!"
baz = jsonpickle.decode(jsonpickle.encode(bar))
baz.hello() # AttributeError: 'Foo' object has no attribute 'hello_fnc'

This was certainly unexpected; apologies if my expectation that (reference to) the function would be preserved is incorrect.

Possibly related to #75; thanks again for your quick turnaround on that!

@davvid davvid closed this in e58f56e Aug 18, 2014

@davvid

This comment has been minimized.

Show comment
Hide comment
@davvid

davvid Aug 18, 2014

Member

We won't be able to support arbitrary functions in general (e.g. lambda), nor instance methods, but free-floating global functions defined inside of a module are now supported.

Member

davvid commented Aug 18, 2014

We won't be able to support arbitrary functions in general (e.g. lambda), nor instance methods, but free-floating global functions defined inside of a module are now supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment