Upcoming Changes in V1 #153
rnag
started this conversation in
Dataclass Wizard V1
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to add my thoughts on planned (breaking) changes in the next major release V1.
Planned Changes
snake_case, then in JSON output it will also be insnake_case.JSONPyWizard, as it was only a stop-gap solution.JSONWizardshould be the default class name, it is time to do away with alias toJSONSerializable, which IMO doesn't make much sense to retain in a library called Dataclass Wizard.__str__()will no longer be default (or at least the same) onJSONWizardsubclass.pydanticdoes it weirdly, it prints the field names withrepr'd values separated by a space, and no class name. Maybe there's a middle ground or it could involve leveragingpprint. I'll have to think on it.floatvalue or a float instr(ex.123.4or'12.3') to anintif the annotated type isint. There seems to be lot of concern over this and it appears to be tied around unintentional data loss, and I agree, we shouldn't lose the fractional part when converting toint, especially as Python we should strive to be more explicit and not do "silent" conversions like these.@dataclassdecorator may no longer be required? For convenience, our library can use@dataclass_transformand apply it ourselves if a class isn't decorated with it. Especially true as most IDEs like PyCharm now support it. I think this would be a huge help for users, and me personally, as I sometimes forget to apply@dataclass.EnvWizardshould be similarly migrated tov1codegen for code quality and also for a performance upgrade, and can leverage thev1loader/dumper process.__pre_as_dict__()hook)Performance improvements
as_str()is unnecessary, simply using builtinstr()appears to be the fastest approach. What a shocker 😮Nonewhen loading tostrtype. Something like'' if x is None else str(x)seems like a good middle ground to have 🤔LoadMixinshould now return a string instead of be defined as regular functions, this will boost performance as we nowexecfunction anyway, so there's no need to nest functions when parsing individual fields.DumpMixinanddumpers.py. My reasoning is, perhaps by default we can use the type annotations on a field to determine how to dump/serialize it. For example, if annotated type isstr | None, then havekwargs[field] = valuein string code to return the field value, no need to check the type of value as howdataclassesdoes it, e.g.if type(obj) in _ATOMIC_TYPES: ...each timeasdictis called. Though my follow-up thought was, it will prove tricky for cases likeOptionalandUnion. ForUniontype annotated fields, maybe it's best to check the type of value directly after all.parsers.pycan be removed, as they will be unnecessary.forloop. I am thinking maybe having aMetasetting such asinput_letter_caseor similar, so e.g. if set toinput_letter_case='CAMEL', then it will enable automatically mapmy_strdataclass field tomyStrin input JSON object. Plus of course, another setting such aswizard_mode=Trueorauto_key_transform=Truewould effectively disable "minor optimization" mode and loop over the input JSON object, as this library is currently doing it, and as the example on the frontpage of the docs clearly illustrates to users.I had more changes planned, if I remember them I will add or jot them down here. Thanks all, and kindly let me know any comments or feedback down below! 👋
Beta Was this translation helpful? Give feedback.
All reactions