Skip to content

Commit

Permalink
Revert some changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollo3zehn committed Dec 8, 2022
1 parent 1971dbd commit 1fe231d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/remoting/python-remoting/nexus_remoting/_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class JsonEncoderOptions:
property_name_encoder: Callable[[str], str] = lambda value: value
property_name_decoder: Callable[[str], str] = lambda value: value

encoders: dict[type, Callable[[Any], Any]] = field(default_factory=lambda: {
encoders: dict[Type, Callable[[Any], Any]] = field(default_factory=lambda: {
datetime: lambda value: value.isoformat().replace("+00:00", "Z"),
timedelta: lambda value: _encode_timedelta(value),
Enum: lambda value: value.name,
UUID: lambda value: str(value)
})

decoders: dict[type, Callable[[type, Any], Any]] = field(default_factory=lambda: {
decoders: dict[Type, Callable[[Type, Any], Any]] = field(default_factory=lambda: {
datetime: lambda _, value: datetime.fromisoformat((value[0:26] + value[26 + 1:]).replace("Z", "+00:00")),
timedelta: lambda _, value: _decode_timedelta(value),
Enum: lambda typeCls, value: cast(Type[Enum], typeCls)[value],
Expand Down Expand Up @@ -86,7 +86,7 @@ def _decode(typeCls: Type[T], data: Any, options: JsonEncoderOptions) -> T:
if typeCls == Any:
return data

origin = typing.cast(type, typing.get_origin(typeCls))
origin = typing.cast(Type, typing.get_origin(typeCls))
args = typing.get_args(typeCls)

if origin is not None:
Expand All @@ -103,7 +103,7 @@ def _decode(typeCls: Type[T], data: Any, options: JsonEncoderOptions) -> T:
elif issubclass(origin, list):

listType = args[0]
instance1: list[Any] = list()
instance1: list = list()

for value in data:
instance1.append(JsonEncoder._decode(listType, value, options))
Expand All @@ -116,7 +116,7 @@ def _decode(typeCls: Type[T], data: Any, options: JsonEncoderOptions) -> T:
# keyType = args[0]
valueType = args[1]

instance2: dict[Any, Any] = dict()
instance2: dict = dict()

for key, value in data.items():
instance2[key] = JsonEncoder._decode(valueType, value, options)
Expand All @@ -136,7 +136,7 @@ def _decode(typeCls: Type[T], data: Any, options: JsonEncoderOptions) -> T:
for key, value in data.items():

key = options.property_name_decoder(key)
parameter_type = typing.cast(type, type_hints.get(key))
parameter_type = typing.cast(Type, type_hints.get(key))

if (parameter_type is not None):
value = JsonEncoder._decode(parameter_type, value, options)
Expand All @@ -160,8 +160,8 @@ def _decode(typeCls: Type[T], data: Any, options: JsonEncoderOptions) -> T:
return instance

# registered decoders
for base in cast(Any, typeCls.__mro__)[:-1]: # need to cast to calm down pyright
decoder = options.decoders[base]
for base in cast(Any, typeCls.__mro__)[:-1]: # need to cast to calm down Pyright
decoder = options.decoders.get(base)

if decoder is not None:
return decoder(typeCls, data)
Expand Down

0 comments on commit 1fe231d

Please sign in to comment.