-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Make Serializer extendable for dependent projects #969
Conversation
decoded_self = obj.from_json(dumped_self) | ||
decoded_srz = json.loads(dumped_srz, cls=Serializer) | ||
|
||
assert decoded_self == decoded_srz == deepcopy(obj) |
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.
А если obj.from_json(dumped_srz)
?
Или json.loads(dumped_self, cls=Serializer)
?
Они тоже будут равны? Аналогично про метод снизу
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.
Думал про это, но у них немного разные сигнатуры.
json.loads
возвращает str
,
а вот obj.to_json
& obj.from_json
работают с Dict[str, Any]
.
Так что нет, равны не будут. Чтобы этого добиться, придется Serializer менять во многих местах, так как он ожидает именно словарики от методов сериализации.
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.
Добавлю пару строк в тесте, чтобы это подчеркнуть
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.
А в теории же obj.to_json
& obj.from_json
могут работать с чем угодно и выдавать тоже что угодно? Или есть какой-то чёткий контракт? Соре, если не заметил в коде
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.
Есть контракт, сигнатура определена в EncodeCallable
& DecodeCallable
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.
Пробовал прогонять эти куски кода через статические анализаторы? А вообще длинная цепочка типов получается
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.
Нет, не прогонял, довольствуюсь встроенными PyCharm проверками. Какой-нибудь mypy у меня не настроен
07da88e
to
2060cdb
Compare
0d45e2f
to
db4dd8f
Compare
Existing Serializer was closed for extension with new classes and so couldn't be reused in GOLEM.
This PR resolves this by allowing registering serializable classes, so that they could be serialized together with default classes.
An example is a serialization of custom graphs that are stored in the OptHistory.
Main changes: