From: Aniket P. <ma...@fe...> - 2020-01-14 05:46:45
|
Hello PyYaml team! Thanks a lot for the amazing tool/library. Great work! Whilst using PyYaml, I had some queries on how the library serializes different objects. For our purposes, we were using the `datetime` library and were having some issues with it. For example, we were dumping a `datetime.date` [0] object and the resultant output showed that it was being serialized as a string, whereas a similar object of type `datetime.time` [1] is being serialized as a binary object ('!!python/object/apply:datetime.time\n- !!binary |\n DAwMAAAA\n'). I am interested in finding out how PyYaml serializes the two very similar classes so differently. Both of these classes have implemented almost the same methods (__str__, __repr__). Logs for more information: ---------------------------------------------------------------------------- # I have used the default dumper, (yaml.dump()) method. >>> d = datetime.date.today() >>> d datetime.date(2020, 1, 14) >>> yaml.dump(d) '2020-01-14\n...\n' >>> datetime.time(12, 12, 12) datetime.time(12, 12, 12) >>> t = datetime.time(12, 12, 12) >>> t datetime.time(12, 12, 12) >>> yaml.dump(t) '!!python/object/apply:datetime.time\n- !!binary |\n DAwMAAAA\n' ---------------------------------------------------------------------------- [0]: https://github.com/python/cpython/blob/3.8/Lib/datetime.py#L789 [1]:https://github.com/python/cpython/blob/3.8/Lib/datetime.py#L1211 -- Thanks Regards Aniket Pradhan http://home.iiitd.edu.in/~aniket17133/ Aliases: MeWjOr/major () ascii ribbon campaign - against html e-mail /\ www.asciiribbon.org - against proprietary attachments P.S. I know I can write a custom dumper for `datetime.time` objects, but was wondering what is the reason that two almost similar classes are being serialized so differently. |