Skip to content

Commit

Permalink
Merge 791c24c into 93ef299
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Aug 11, 2020
2 parents 93ef299 + 791c24c commit b19ec05
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
# 0.11 (beta)

- Added support to treat `Mapping` type annotations as dictionaries.
- Fixed handling of default values for `dataclass` attributes.

# 0.10 (2020-07-03)

Expand Down
5 changes: 4 additions & 1 deletion datafiles/converters/containers.py
@@ -1,3 +1,4 @@
import dataclasses
from collections.abc import Iterable
from contextlib import suppress
from typing import Callable, Dict
Expand Down Expand Up @@ -133,7 +134,9 @@ def of_mappings(cls, dataclass, converters: Dict[str, type]):

@classmethod
def to_python_value(cls, deserialized_data, *, target_object):
if isinstance(deserialized_data, dict):
if dataclasses.is_dataclass(deserialized_data):
data = dataclasses.asdict(deserialized_data)
elif isinstance(deserialized_data, dict):
data = deserialized_data.copy()
else:
data = {}
Expand Down
1 change: 1 addition & 0 deletions datafiles/tests/test_converters.py
Expand Up @@ -158,6 +158,7 @@ def when_immutable(expect, converter, data, value):
(MyDict, {}, {}),
(MyDict, {'a': 1}, {'a': 1}),
(MyDataclassConverter, None, MyDataclass(foobar=0)),
(MyDataclassConverter, MyDataclass(42), MyDataclass(foobar=42)),
(MyDataclassConverterList, None, []),
(MyDataclassConverterList, 42, [MyDataclass(foobar=0)]),
],
Expand Down
120 changes: 105 additions & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,7 +1,7 @@
[tool.poetry]

name = "datafiles"
version = "0.11b1"
version = "0.11b2"
description = "File-based ORM for dataclasses."

license = "MIT"
Expand Down

0 comments on commit b19ec05

Please sign in to comment.