Skip to content
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

msgspec.from_builtins -> msgspec.convert #431

Merged
merged 11 commits into from
Jun 7, 2023
Merged

msgspec.from_builtins -> msgspec.convert #431

merged 11 commits into from
Jun 7, 2023

Conversation

jcrist
Copy link
Owner

@jcrist jcrist commented Jun 7, 2023

This is a major overhaul of the existing msgspec.from_builtins function.

In short: the capabilities of msgspec.from_builtins have been expanded to support a wider range of input types (the full set of types supported by other msgspec functions). To better match the new capabilities, msgspec.from_builtins function has been renamed to msgspec.convert, with the old name deprecated.

Summary:

  • msgspec.from_builtins has been deprecated and renamed to msgspec.convert. The capabilities of convert are a superset of those of the old from_builtins. Note that some of the keyword arguments have changed names.
  • The coercion behavior in from_builtins available by setting str_values=True is now renamed to strict=False in msgspec.convert. Setting strict=False enables 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.
  • The attributes kwarg added in Add attributes option to from_builtins #419 has been renamed to from_attributes. Since this feature hasn't been released yet, this is not a breaking change.
  • msgspec.convert now 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.

jcrist added 11 commits June 5, 2023 23:15
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.
@jcrist jcrist merged commit b36a092 into main Jun 7, 2023
@jcrist jcrist deleted the msgspec-convert branch June 7, 2023 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant