[Python-ideas] Re: JSON encoder protocol

2019-08-17 Thread Christopher Barker
> > But it does become worse if you have lots of classes you want to > serialize. You need to write a default function somewhere that knows about > all of your classes: > Somehow I didn't think of this until now, but when I've needed to use JSON to serialize a non-trivial hierachy of types, I' es

[Python-ideas] Re: Fwd: Optional kwarg for sequence methods in random module

2019-08-17 Thread Andrew Barnert via Python-ideas
On Aug 17, 2019, at 00:02, Patryk Gałczyński wrote: > > One thing I'm concern about is how it would all relate to _randommodule.c (I > have little knowledge about C part) You probably don’t need to change the C code at all. I’m pretty sure none of these functions are implemented in C, they jus

[Python-ideas] Fwd: Optional kwarg for sequence methods in random module

2019-08-17 Thread Patryk Gałczyński
Hi! Recently I encountered a situation when I needed to pick a random population sample but with specific distribution function - paretovariate in this particular case. After poking around in the random module I found out that none of the so-called "sequence methods" methods support custom random

[Python-ideas] Re: JSON encoder protocol

2019-08-17 Thread Paul Moore
On Sat, 17 Aug 2019 at 08:28, Andrew Barnert via Python-ideas wrote: > def jsonize_my_tree(obj): > if isinstance(obj, MyTreeNode): > return [obj.data(), *map(jsonize_my_tree, obj.children())] > raise TypeError() > > myjson = json.dumps(my_thing_that_might_includ

[Python-ideas] Re: JSON encoder protocol

2019-08-17 Thread Kyle Stanley
Ah, that makes sense, thank you for the detailed example and explanation. I had only read through the start of the previous topic, as it started to become a bit difficult to follow (largely due to the author being non-specific with what precisely they were looking for and the discussion forking off

[Python-ideas] Re: JSON encoder protocol

2019-08-17 Thread Andrew Barnert via Python-ideas
On Aug 16, 2019, at 20:35, Kyle Stanley wrote: > > Speaking of examples, I think it would be helpful to provide a brief example > of ``object.__json__()`` being used for some added clarity. Would it be a > direct alias of ``json.dumps()`` with the same exact parameters and usage, or > would th