New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Methods to convert to/from builtin objects #189
Comments
Maybe just implement |
The first half of this ( |
This proposal looks like transforming an entire object? Maybe I don't follow the reasoning. I'm looking to override behavior on a single type
is really annoying in other JSON libs! thanks for adding here. |
Thanks Jim!
…On Jan 17, 2023 at 7:31:10 PM, Jim Crist-Harif ***@***.***> wrote:
Closed #189 <#189> as completed
via #266 <#266>.
—
Reply to this email directly, view it on GitHub
<#189 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKAOIQSDCVRUHJMKSV7R23WS5BV5ANCNFSM6AAAAAAQPTCMSA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
msgspec
currently contains methods for converting converting objects to/from bytes using either JSON or MessagePack protocols. Sometimes it'd be useful to convert to/from "simpler" types (lists, dicts, ...).Example use cases:
pyyaml
. This can currently be handled on the encoding end by passing in a customdefault
method, but if the encode call is buried in some wrapper library the user may not have access to it directly and would need to recursively simplify the object before handing it off.pyyaml
into higher-level types, while keeping the type validation. The easiest way to do this right now is to roundtrip the message through a supported protocol, for example:Proposed initial API:
I'm not 100% happy with this names, but all other options I could think of I liked less:
to_simple
/from_simple
simplify
/convert
(I don't like the asymmetry in name here, andconvert
implies some casting behaviors likefloat -> int
that we won't actually support)cattrs
calls thesedestructure
/structure
respectivelylower
/lift
(for converting to lower/higher level types)A few open questions:
to_builtins
? My initial reaction isdict
,list
,tuple
,str
,int
,float
,bool
,None
(and no subclasses).bytes
/bytearray
anddatetime
currently (we wouldn't supportExt
/Raw
in this API anyway)? Perhapsconvert_binary=True
andconvert_datetime=True
flags into_builtins
?If anyone has thoughts on how to spell these APIs, please let me know below.
The text was updated successfully, but these errors were encountered: