[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread J. Pic
I published a lib on PyPi that does that, which pushed to write a complete readme, that I will reproduce here if anybody is interested in more discussion about this, along with my conclusions: Overall, it seems like the cost of maintenance is going to be insignificant. While the value is reduced

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread J. Pic
Or, there might be a way to get the best of both worlds. Consider this silly example: encoded = yourobject.__jsondump__() # this should work yourobject == YourClass.__jsonload__(encoded) Basically very similar to __getstate__ and __setstate__ with pickle, with the following

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread Dan Sommers
On Wednesday, June 10, 2020, at 10:37 -0500, Chris Angelico wrote: On Thu, Jun 11, 2020 at 1:35 AM Eric V. Smith wrote: On 6/10/2020 11:00 AM, Chris Angelico wrote: > On Thu, Jun 11, 2020 at 12:45 AM Dan Sommers > <2qdxy4rzwzuui...@potatochowder.com> wrote: >> If you control both the

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread Eric V. Smith
On 6/10/2020 11:59 AM, J. Pic wrote: > I don't think the stdlib needs to cater to that requirement > when there are hooks to write your own customizations. If the stdlib offers such hooks, as well as objects that don't serialize by default, why not ship a usable hook that would serialize

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread J. Pic
> I don't think the stdlib needs to cater to that requirement > when there are hooks to write your own customizations. If the stdlib offers such hooks, as well as objects that don't serialize by default, why not ship a usable hook that would serialize anything from the stdlib by default ? It

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread Chris Angelico
On Thu, Jun 11, 2020 at 1:35 AM Eric V. Smith wrote: > > On 6/10/2020 11:00 AM, Chris Angelico wrote: > > On Thu, Jun 11, 2020 at 12:45 AM Dan Sommers > > <2qdxy4rzwzuui...@potatochowder.com> wrote: > >> If you control both the producers and the consumers, and they're > >> both written in Python,

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread Eric V. Smith
On 6/10/2020 11:00 AM, Chris Angelico wrote: On Thu, Jun 11, 2020 at 12:45 AM Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: If you control both the producers and the consumers, and they're both written in Python, then you may as well use pickle and base64 (and an HMAC!) to convert

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread J. Pic
> Why bother with JSON and all of its verbosity and restrictions in the first place? Well PostgreSQL offers query abilities on JSON fields nowadays, so that's the reason I've been migrating stuff from pickle to json, because then I can query on the data.

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread Chris Angelico
On Thu, Jun 11, 2020 at 12:45 AM Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: > If you control both the producers and the consumers, and they're > both written in Python, then you may as well use pickle and base64 > (and an HMAC!) to convert your python data to an opaque ASCII > string

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread Dan Sommers
On Wednesday, June 10, 2020, at 08:48 -0500, Alex Hall wrote: On Wed, Jun 10, 2020 at 3:42 PM J. Pic wrote: I understand, do you think the python standard library should provide a JSONEncoder and JSONDecoder that supports python standard library objects ? It would be optional to use,

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread Eric V. Smith
On 6/10/2020 9:48 AM, Alex Hall wrote: On Wed, Jun 10, 2020 at 3:42 PM J. Pic > wrote: I understand, do you think the python standard library should provide a JSONEncoder and JSONDecoder that supports python standard library objects ? It would be

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread Bar Harel
Since there's no standard for this in json, deciding to serialize to str is quite arbitrary. I personally serialize UUIDs to binary data as it takes less space. Some serialize it to hexadecimal. Tbh, it sounds like a good idea but can have it's pitfalls. On Wed, Jun 10, 2020, 4:43 PM J. Pic

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread Alex Hall
On Wed, Jun 10, 2020 at 4:09 PM J. Pic wrote: > Good point, but then I'm not sure the decoder could be used for untrusted > json anymore. > > Another solution would be to generate a schema in a separate variable, > which would represent the JSON structure with Python types. > For that there are

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread J. Pic
Good point, but then I'm not sure the decoder could be used for untrusted json anymore. Another solution would be to generate a schema in a separate variable, which would represent the JSON structure with Python types. Also, there's still simple regexp pattern matching that could also be good

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread Alex Hall
On Wed, Jun 10, 2020 at 3:42 PM J. Pic wrote: > I understand, do you think the python standard library should provide a > JSONEncoder and JSONDecoder that supports python standard library objects ? > > It would be optional to use, but if you use it then any object from the > python standard

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread J. Pic
I understand, do you think the python standard library should provide a JSONEncoder and JSONDecoder that supports python standard library objects ? It would be optional to use, but if you use it then any object from the python standard library will just work.

[Python-ideas] Re: JSON Serializing UUID objects

2020-06-10 Thread Pablo Alcain
I don't know how or even whether this would be possible ootb. On one side, I do really like the idea; on the other hand, it kind of seems like going down a bumpy road (as you said, datetimes? filepaths?urls?). And the de-serialization would not be easy. What if we added a function call for the