mverleg / pyjson_tricks

Extra features for Python's JSON: comments, order, numpy, pandas, datetimes, and many more! Simple but customizable.
Other
152 stars 23 forks source link

Fix error in __slots__ support of the __weakref__ attribute #83

Closed dominicdoty closed 1 year ago

dominicdoty commented 1 year ago

Fix for #82

Tests passing in Python 3.7.9

dominicdoty commented 1 year ago

ran test pipelines on my fork, all passed:

https://github.com/dominicdoty/pyjson_tricks/actions/runs/3365444659

mverleg commented 1 year ago

Thanks for providing a solution! I think I'll make some slight changes, because I'd prefer to handle this when encoding instead of decoding.

dominicdoty commented 1 year ago

I figured it maybe is a valid thing to encode and then confirm that the new object has the same attribute, since you potentially could have different behavior if someone changed the class definition to not include the __weakref__ attribute before decoding in a different environment.

But, that's probably too much of a corner case to care about.

If anyone finds this in the future because they have some jsons with this encoded in already - you can simply delete the __weakref__ attribute from your json to fix it.

mverleg commented 1 year ago

Definitely something to be said for having json debug-able, and for supporting existing exports.

But in this case I think I prefer more strongly to have the json as clean as possible, and not require weakrefs to be encode-able.

dominicdoty commented 1 year ago

Works for me!

Thanks for taking care of this, glad to have it fixed either way.