Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-merzky committed Apr 6, 2024
1 parent b5af2d0 commit 9095c33
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
15 changes: 7 additions & 8 deletions src/radical/utils/serialize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import copy
import json
import msgpack

Expand All @@ -16,6 +15,7 @@ def __init__(self, ctype, encode, decode):
self.encode: callable = encode
self.decode: callable = decode


_ctypes = dict()


Expand All @@ -34,14 +34,12 @@ def register_serializable(cls, encode=None, decode=None):
if encode is None: encode = cls
if decode is None: decode = cls

global _ctypes
_ctypes[cls.__name__] = _CType(cls, encode, decode)


# ------------------------------------------------------------------------------
#
def _prep_typed_dict(d):
from .typeddict import as_dict
return as_dict(d, _annotate=True)


Expand All @@ -56,13 +54,14 @@ def encode(self, o, *args, **kw):
tmp = as_dict(o, _annotate=True)
return super().encode(tmp, *args, **kw)

def default(self, obj):
# print('encode: %s' % obj)
def default(self, o):
# print('encode: %s' % o)
for cname,methods in _ctypes.items():
if isinstance(obj, methods.ctype):
if isinstance(o, methods.ctype):
return {'_type': cname,
'as_str': methods.encode(obj)}
return super().default(obj)
'as_str': methods.encode(o)}
return super().default(o)


# ------------------------------------------------------------------------------
#
Expand Down
1 change: 0 additions & 1 deletion src/radical/utils/typeddict.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# - optional runtime type checking
#

import collections
import copy
import sys

Expand Down
2 changes: 1 addition & 1 deletion src/radical/utils/zmq/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict, Any

from ..typeddict import TypedDict
from ..serialize import to_msgpack, from_msgpack, register_serializable
from ..serialize import to_msgpack, from_msgpack


# ------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# noqa: E201


import radical.utils as ru
# import radical.utils as ru


# ------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class B(ru.TypedDict):
new = ru.from_json(ru.to_json(old))

assert old == new
assert type(old) == type(new)
assert type(old['a']) == type(new['a'])
assert isinstance(old, B) and isinstance(new, B)
assert isinstance(old['a'], A) and isinstance(new['a'], A)


# ------------------------------------------------------------------------------
Expand Down

0 comments on commit 9095c33

Please sign in to comment.