All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Add link to docs in readme
- In-depth documentation. Lots of docstring updates!
serdelicacy.SerdeError
as part of the public API (mostly for documentation)
- Explicit support for
enum.Enum
and its subtypes. I personally prefertyping.Literal
, butenum.Enum
might be preferred by others.
Note: breaking changes regarding validation and transformation.
- Provide
Override
type, which provides metadata user-defined overrides for dataclass serde for the namespace-constrainedserdelicacy
key. Prevents namespace pollution and provides more type safety.
- Keys
transform_load
,transform_postload
, andvalidate
are no longer expected. Instead, use the keyserdelicacy
and pass it aserdelicacy.Override
object.
- Support for additional
dataclasses.field
metadata
keys:transform_load
,transform_postload
, andtransform_dump
. These enable the user to specify functions to modify the specific value that is deserialized (loaded) and serialized (dumped).
- Inconsistent documentation the referred to
UNDEFINED
has been corrected to refer toMISSING
.
- Removed automatic conversion for primitive types. This special case created a lot of code complexity and is arguably unnecessary now that we provide support for validations and transformations with
dataclasses
.
- Major validation improvement! Support for dataclass attribute validation using the
metadata
parameter todataclasses.field
, likedataclasses.field(metadata={"validate": str.istitle})
. The function passed as the mapping value should either returnTrue
on positive validation /False
on non-validation, or return nothing at all and instead rely on the raising of exceptions to indicate whether validation passed for failed.
- Support for deserialization of
typing.Literal
. Lets users to specify an allow-list for string / other input values, removing an entire category of annoying custom validation that users previously needed to write in__post_init__
.
- New Public API function
serdelicacy.get
. Similar todict.get
, that returns an item, or its default if the item isMISSING
.
- Error messages modified for terseness
- Error message JSON keys are now color encoded to draw visual attention to errors: green/blue for normal, red for the error
- Error messages now in JSON format with better-organized information
- Resolved bug where
str
was converted automatically to a List / other sequence. Sincestr
is a special-case primitive, we must handle it as a special case within the_check_sequence
method.
is_missing
function added to serdelicacy
UNDEFINED/Undefined
changed toMISSING/Missing
- Project name changed from
serdataclasses
toserdelicacy
. This reflects this project's evolution beyond simplydataclasses
intoNamedTuples
, etc. Version0.9.0
is equivalent toserdataclasses
0.8.0
in every other way.
Major changes in this release!
- (potential breaking change) add OptionalProperty, UNDEFINED, and Undefined for missing properties. If your code currently relies on
None
being generated bytyping.Optional
on missing properties, read the function signature ofload
anddump
.
- Error messages are generally much better
- Better-handle custom exceptions being raised in dataclasses. Useful to elegantly hande validation checks in
__post_init__
- Type improvements for NoResult
- Support for automatic conversion of primitive types (
str
,int
,float
,bool
). Stops the conversion when hitting all non-Option
Union
types.
object
types were incorrectly specified, they have been changed toAny
.- Update pylint and mypy for local debugging purposes
- Support default arguments for
NamedTuples
anddataclasses
. Behavior: if default argument exists, if no argument is present in the unstructure Python object, and if there is a default value for the argument, we use the default argument instead ofNone
(which is automatically returned bydict.get
).
There are no functional changes here, just some book-keeping CI / local dev-related stuff.
- Set up continuous integration using GitHub Actions.
- Some development dependencies weren't in pyproject.toml.
load
now supportstuple
typesdump
now supports Sequence/Mapping, not just list/dict
- Keywords and classifiers to
pyproject.toml
.
- Lists and Dicts in
deserialize.load
have been generalized into the generic protocolstyping.Sequence
andtyping.Mapping
. typing.get_origin
andtyping.get_args
are now call called only once in the Deserialize constructor.
- Support for
typing.TypedDict
typesafe_constructor
argument todeserialize.load
to optionally ensure type safety at the top-level. It defaults to True.
- This
CHANGELOG.md
deserialize.load
,deserialize.DeserializeError
, andserialize.dump
are imported at the top-level.- Support for NamedTuple and Dict
- Add
py.typed
to package (PEP 561) typedefs.NoResult
andtypedefs.Possible
. This is a bespoketyping.Optional
implementation becauseNone
is a value we actually care about.
deserialize.deserialize
changed todeserialize.load
serialize.serialize
changed toserialize.dump
- The
deserialize._deserialize
function is replaced bydeserialize.Deserialize
. - Removed "vaporware" designation: this is now a real project.
mypy
,pylint
,black
,toml-sort
, andisort
all pass.
- Recursive types. I may add them again in the future when
mypy
supports them, but given the sketchyness of the type system at present, I'm not confident that they'll actually help