Can we delete the "default_used" flag?
steverpalmer opened this issue · 1 comments
When packing, there is a "default_used" flag that is set after the Packer._default is called from Packer._pack. This prevents a second invocation of Packer._default.
In my use case, I would like to have Packer._default return an object which is, in some sense, closer to something that can be packed, but may need further invocation(s) of Packer._default on the returned item. Of course, if I handled this badly, then it could result in a infinite recursion, but perhaps this is my problem. Alternatively, if it is felt that preventing an infinite recursion is a requirement of the function of packing, then perhaps a counter like the nest_limit that would limit the number of calls to Packer._default may be used. The current default_used flag essentially limits the call depth to 1, which in my use case is too restrictive.
As a test, I forced the use of the fallback.py version and deleted all references to default_used, and the code worked as required.
So, can we delete the "default_used" flag?
This option is provided for stdlib json compatibility.
If specified, default should be a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError. If not specified, TypeError is raised.
-- https://docs.python.org/3.12/library/json.html
You need to wrap your default function with function that calls default function several times.