-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for dataclass serialisation
- Loading branch information
Showing
4 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
# from .numpy import registry as numpy | ||
try: | ||
from .numpy import registry as numpy | ||
except ImportError: | ||
numpy = None | ||
|
||
from .pickle import registry as pickle | ||
from .base import registry as base | ||
from .as_dict import AsDict | ||
from .namedtuple import registry as namedtuple | ||
from .registry import (Registry, Serialiser, RefObject) | ||
from .reasonable import (Reasonable) | ||
from .path import SerPath | ||
|
||
__all__ = ['pickle', 'base', 'Registry', 'Serialiser', 'SerPath', | ||
'RefObject', 'AsDict', 'namedtuple', 'Reasonable'] | ||
'RefObject', 'AsDict', 'namedtuple', 'Reasonable', 'numpy'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import dataclasses | ||
from .registry import Serialiser | ||
|
||
|
||
class SerDataClass(Serialiser): | ||
def __init__(self): | ||
super(SerDataClass, self).__init__('<dataclass>') | ||
|
||
def encode(self, obj, make_rec): | ||
return make_rec(obj.__dict__) | ||
|
||
def decode(self, cls, data): | ||
return cls(**data) |