harbor run -t swe-rebench/jsonpickle__jsonpickle-587
harbor download swe-rebench/jsonpickle__jsonpickle-587
Serializing an object with __slots__ ignores _jsonpickle_exclude To reproduce (Python 3.12, jsonpickle 4.1.1):
__slots__
_jsonpickle_exclude
import jsonpickle class Foo: __slots__ = ("bar", "secret") _jsonpickle_exclude = {"secret"} def __init__(self, bar, secret): self.bar = bar self.secret = secret foo = Foo(1, 42) print(jsonpickle.dumps(foo)) # '{"py/object": "__main__.Foo", "bar": 1, "secret": 42}'
This issue arose for me when used in combination with attr.define, which defines __slots__, and unpicklable=False (otherwise __state__ is used).
attr.define
unpicklable=False
__state__
import jsonpickle, attr @attr.define class AttrFoo: bar: str secret: str _jsonpickle_exclude = {"secret"} foo2 = AttrFoo(1, 42) jsonpickle.dumps(foo2, unpicklable=False) # '{"bar": 1, "secret": 42}'
Note: for this second case there is a simple workaround, which is to not define slots attr.define(slots=False).
attr.define(slots=False)