Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Valentin Féron
committed
Apr 4, 2023
1 parent
d69c251
commit 5d88378
Showing
1 changed file
with
13 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5d88378
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
to_jdict
andfrom_jdict
thing.I know, I standard that trend in CentroidSmoothing.
It has its advantages (we can just ask the object itself to give us a jsonizable dict, or make itself with one).
But it also has some draw backs.
For one, it’s not separating the classes’ main purpose(s) and the json-serialization concern.
There are other options.
Still not separating the serialization concern, but doing it the python way, would be to use
instead. But note that then
pickle
would use that too, which is maybe not what we want.One of the purposes of
py2json
is to make it easy(er) to externalize the json-serialization concern. We could, for example,json
lib to informjson.load
andjson.dump
about the codec to use at the point we need to.5d88378
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I know it is not ideal.
We could put this logic into a decorator to add those methods. It is not ideal either becuase, sometimes, you just want to serialize an object without having to decorate it first to make sure it is serializable.
Regarding the
__setstate__
/__getstate__
solution, yes, it sounds dangerous to change the way pickle will serialize it. But it also sounds consistent to have only one way to serialize a class.