Releases: yukinarit/pyserde
v0.10.0
What's Changed
New features
pyserde can (de)serialize dataclasses without @serde
since v0.10.0. This feature is convenient when you want to use classes declared in external libraries or a type checker doesn't work with @serde
decorator. See this example. Thanks @Kobzol!
@dataclass
class Foo:
i: int
s: str
f: float
b: bool
f = Foo(i=10, s='foo', f=100.0, b=True)
print(f"Into Json: {to_json(f)}")
s = '{"i": 10, "s": "foo", "f": 100.0, "b": true}'
print(f"From Json: {from_json(Foo, s)}")
- Generate serialization/deserialization code for dataclasses not marked with @serde by @Kobzol in #312
- Use default options for unmarked dataclass code generation by @Kobzol in #314
- Allow serializing and deserializing root dataclasses by @Kobzol in #315
Bug fixes
- Fix deserialization with NewType and Untagged Union by @yukinarit in #313
CI
- Set commit author and title for commits in gh-pages by @yukinarit in #316
Documentation
- Migrate to Github's changelog by @yukinarit in #311
- Update contributors by @yukinarit in #317
- Document (de)serializing dataclasses without @serde by @yukinarit in #319
New Contributors
Full Changelog: v0.9.8...v0.10.0
v0.9.8
What's Changed
New features
- feat: Support optional ClassVar serialization by @yukinarit in #303
CI
- Add .github/release.yml by @yukinarit in #304
- Update CI scripts by @yukinarit in #305
- Upgrade to setup-python@v4 and enable caching by @yukinarit in #306
- Upgrade codecov-action to v3 by @yukinarit in #307
- Publish with Github Actions by @yukinarit in #310
Other changes
- Bump to 0.9.7 by @yukinarit in #295
- style: Fix styles and reformat code by @yukinarit in #299
- chore: Rename branch from master to main by @yukinarit in #300
Full Changelog: v0.9.7...v0.9.8
v0.9.7
A bug for optional unions was fixed, Thanks @soaxelbrooke!
@serde
@dataclass(frozen=True)
class Bar:
request: Optional[Union[str, int]]
- docs: add @soaxelbrooke as a contributor (063e705)
- Add support for optional unions (075949b)
- Add typing-utils for compatibility with python ver < 3.8 (620b9f6)
- Rely on compay.get_args instead of adding dependency (d93f894)
v0.9.6
- Recursive dataclasses are supported in #290
@dataclass class Recur: f: Optional['Recur'] serde(Recur)
typing.FrozenSet
andtyping.DefaultDict
are supported in #285,#286@serde @dataclass class Foo: a: FrozenSet[int] b: DefaultDict[str, List[int]]
- Pickle serializer and deserializer support is added in #284. Thanks @DoeringChristian!
Full Changelog: v0.9.5...v0.9.6
v0.9.5
v0.9.4
v0.9.3
Thanks to PEP681 @dataclass_transform, @dataclass
decorator is no longer mandatory if you use a PEP681 supported type checker such as pyright. If you are a mypy user, you still need @dataclass
decorator.
@serde
#@dataclass <= No longer needed.
class Foo:
i: int
v0.9.2
v0.9.1
v0.9.0
pyserde
v0.9 adds one of the most awaited features, the type checking functionality 🎉 If you add Coerce
or Strict
in serde
decorator, pyserde
will do type coercing or type checking based on the declared types.
Coerce
Type coercing automatically converts a value into the declared type during (de)serialization. If the value is incompatible e.g. value is "foo" and type is int, pyserde raises an SerdeError
.
@serde(type_check=Coerce)
@dataclass
class Foo
s: str
foo = Foo(10)
# pyserde automatically coerce the int value 10 into "10".
# {"s": "10"} will be printed.
print(to_json(foo))
Strict
Strict type checking is to check every value against the declared type during (de)serialization. We plan to make Strict
a default type checker in the future release.
@serde(type_check=Strict)
@dataclass
class Foo
s: str
foo = Foo(10)
# pyserde checks the value 10 is instance of `str`.
# SerdeError will be raised in this case because of the type mismatch.
print(to_json(foo))
- refactor: Change default type_check from Coerce to NoCheck (23ea180)
- refactor: Change to pass "type_check" parameter in decorator (fbe8dc8)
- feat: Add type coercion feature make it default (dabb777)
- feat: Implement strict type checking (0273b9a)
Another notable change is switching toml library from toml to tomli. tomli is used in a handful of major products e.g. pip
and pytest
and will be the part of Python standard library in Python 3.11.
- feat: Switch toml library to tomli (11b4df6)
- Better documentation about generic alias (fd4e5a5)
- Ensure union_func_name produces a valid function name (eddf250)
- Import 'Literal' from serde.compat (a7450c1)
- Support NumPy 1.23 in Python 3.7/3.8 (3309a73)
- Use str instead of repr in typename, fixing Union[Literal["str"], ...] (b3905ef)
- fix: from_json return returns T not Optional[T] (9e50fb7)
This release had contributions from 1 person: @kngwyu. Thank you so much! 🎉 😂