You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jsonpickle is not able to correctly decode decorated functions that return an object.
Here's the minimal reproducible example:
importjsonpickleclassFuncNested:
def__init__(self, func) ->None:
self.func=funcdef__call__(self, *args, **kwargs):
returnself.func(*args, **kwargs)
defnester(func):
returnFuncNested(func)
@nesterdefbro():
return"Mate"# Check that original object is a FuncNested objectasserttype(bro) isFuncNested# Check that the `.func` member variable of the original object is NOT a FuncNested object. asserttype(bro.func) isnotFuncNestedencoded_bro_str=jsonpickle.encode(bro)
print(encoded_bro_str)
>> {"py/object": "__main__.FuncNested", "func": {"py/function": "__main__.bro"}}
decoded_bro=jsonpickle.decode(encoded_bro_str)
# Check that decoded object is also a FuncNested objectasserttype(decoded_bro) isFuncNested# Check that the `.func` member variable of decoded object is NOT a FuncNested object. asserttype(decoded_bro.func) isnotFuncNested# <-- This fails>>--------------------------------------------------------------------------->>AssertionErrorTraceback (mostrecentcalllast)
>>CellIn[29], line26>>24asserttype(decoded_bro) isFuncNested>>25# Check that the `.func` member variable is NOT a FuncNested object. >>--->26asserttype(decoded_bro.func) isnotFuncNested# <-- This fails>>>>AssertionError:
The text was updated successfully, but these errors were encountered:
That's really interesting, thanks for reporting! I did a bit of further digging, and it seems that before bro gets encoded, bro.func is of type function, and after it is of type FuncNested (the latter being obvious). I think it could be fixed by going back in FuncNested's mro once before it's returned to the user, but I'll need to check later because I'm supposed to be paying attention in class instead of doing unrelated stuff 😅
Hi,
jsonpickle is not able to correctly decode decorated functions that return an object.
Here's the minimal reproducible example:
The text was updated successfully, but these errors were encountered: