Skip to content

Commit

Permalink
feat: Automatically put dataclass decorator
Browse files Browse the repository at this point in the history
if @DataClass decorator not found, put it automatically
  • Loading branch information
yukinarit committed Nov 26, 2021
1 parent 758cce5 commit 2f0cf01
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions serde/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def deserialize(
"""

def wrap(cls: Type):
# If no `dataclass` found in the class, put it automatically.
if not is_dataclass(cls):
cls = dataclass(cls)

g: Dict[str, Any] = {}

# Create a scope storage used by serde.
Expand Down
4 changes: 4 additions & 0 deletions serde/se.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ def serialize(
"""

def wrap(cls: Type):
# If no `dataclass` found in the class, put it automatically.
if not is_dataclass(cls):
cls = dataclass(cls)

g: Dict[str, Any] = {}

# Create a scope storage used by serde.
Expand Down
10 changes: 4 additions & 6 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,10 @@ class C:


def test_non_dataclass():
with pytest.raises(TypeError):

@deserialize
@serialize
class Foo:
i: int
@deserialize
@serialize
class Foo:
i: int


# test_string_forward_reference_works currently only works with global visible classes
Expand Down

0 comments on commit 2f0cf01

Please sign in to comment.