msgspec.from_builtins -> msgspec.convert - #431
Merged
Merged
Conversation
This renames `msgspec.from_builtins` to `msgspec.convert`, keeping around a deprecated version of `from_builtins` that warns and forwards its arguments to `convert`. Since `from_builtins` now supports inputs from non-builtin types, the old name no longer makes sense.
This renames the `str_values` kwarg in `from_values` to `strict` (and inverts the default). This is preparation for adding `strict=False` support to all builtin decoders, enabling opt-in behavior to more flexible parsing.
This is a better keyword name (and also happens to match the one used by pydantic V2). This isn't a breaking change since this feature has yet to be released.
If we need to support converting to the original attribute names, we can add another config option later. Using the renamed names provides better uniformity across the library.
This also adds support for coercing str subclasses to any str-like value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a major overhaul of the existing
msgspec.from_builtinsfunction.In short: the capabilities of
msgspec.from_builtinshave been expanded to support a wider range of input types (the full set of types supported by othermsgspecfunctions). To better match the new capabilities,msgspec.from_builtinsfunction has been renamed tomsgspec.convert, with the old name deprecated.Summary:
msgspec.from_builtinshas been deprecated and renamed tomsgspec.convert. The capabilities ofconvertare a superset of those of the oldfrom_builtins. Note that some of the keyword arguments have changed names.from_builtinsavailable by settingstr_values=Trueis now renamed tostrict=Falseinmsgspec.convert. Settingstrict=Falseenables a laxer set of coercion rules (msgspec is strict by default). The intent is to support this kwarg in all decoders in a follow-up PR.attributeskwarg added in Addattributesoption tofrom_builtins#419 has been renamed tofrom_attributes. Since this feature hasn't been released yet, this is not a breaking change.msgspec.convertnow supports any supported type as input. For the most part non-python-builtin types (e.g. dataclasses, attrs, ...) won't coerce to any other types, but will be type checked.Note that the prose documentation hasn't been updated yet, this will done in a follow-up PR before the next release, once the remaining refactor changes have landed.