Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dkraczkowski committed May 28, 2024
1 parent 0af3249 commit 679be73
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
14 changes: 10 additions & 4 deletions chili/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def _build_type_decoder(self, a_type: Type) -> TypeDecoder:
map_generic_type(a_type, self._generic_parameters),
self._extra_decoders,
self._generic_type.__module__,
self.force
self.force,
)


Expand Down Expand Up @@ -444,7 +444,9 @@ def decode(self, value: list) -> tuple:
def _build(self) -> None:
field_types = self.class_name.__annotations__
for item_type in field_types.values():
self._arg_decoders.append(build_type_decoder(item_type, self._extra_decoders, self.class_name.__module__, self.force))
self._arg_decoders.append(
build_type_decoder(item_type, self._extra_decoders, self.class_name.__module__, self.force)
)


class TypedDictDecoder(TypeDecoder):
Expand All @@ -453,7 +455,9 @@ def __init__(self, class_name: Type, extra_decoders: TypeDecoders = None, force:
self._key_decoders = {}
self._extra_decoders = extra_decoders
for key_name, key_type in class_name.__annotations__.items():
self._key_decoders[key_name] = build_type_decoder(key_type, self._extra_decoders, class_name.__module__, force)
self._key_decoders[key_name] = build_type_decoder(
key_type, self._extra_decoders, class_name.__module__, force
)

def decode(self, value: dict) -> dict:
return {key: self._key_decoders[key].decode(item) for key, item in value.items()}
Expand Down Expand Up @@ -546,7 +550,9 @@ def build_type_decoder(
return Decoder[origin_type](decoders=extra_decoders) # type: ignore

if is_optional(a_type):
return OptionalTypeDecoder(build_type_decoder(unpack_optional(a_type), extra_decoders, module, force)) # type: ignore
return OptionalTypeDecoder(
build_type_decoder(unpack_optional(a_type), extra_decoders, module, force) # type: ignore
)

if origin_type not in _supported_generics:
if force and is_class(origin_type):
Expand Down
10 changes: 7 additions & 3 deletions chili/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _build_type_encoder(self, a_type: Type) -> TypeEncoder:
map_generic_type(a_type, self._generic_parameters),
self._extra_encoders,
self._generic_type.__module__,
self.force
self.force,
)


Expand Down Expand Up @@ -318,7 +318,9 @@ def encode(self, value: tuple) -> list:
def _build(self) -> None:
field_types = self.type.__annotations__
for item_type in field_types.values():
self._arg_encoders.append(build_type_encoder(item_type, self._extra_encoders, self.type.__module__, self.force))
self._arg_encoders.append(
build_type_encoder(item_type, self._extra_encoders, self.type.__module__, self.force)
)


class TypedDictEncoder(TypeEncoder):
Expand All @@ -327,7 +329,9 @@ def __init__(self, class_name: Type, extra_encoders: TypeEncoders = None, force:
self._key_encoders = {}
self.force = force
for key_name, key_type in class_name.__annotations__.items():
self._key_encoders[key_name] = build_type_encoder(key_type, extra_encoders, class_name.__module__, self.force)
self._key_encoders[key_name] = build_type_encoder(
key_type, extra_encoders, class_name.__module__, self.force
)

def encode(self, value: dict) -> dict:
return {key: self._key_encoders[key].encode(item) for key, item in value.items()}
Expand Down
5 changes: 3 additions & 2 deletions chili/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
from functools import lru_cache
from inspect import isclass as is_class
from typing import Any, Callable, ClassVar, Dict, List, NewType, Optional, Type, Union, get_type_hints
from chili.error import SerialisationError

from chili.error import SerialisationError

try:
from types import UnionType
from types import UnionType # type: ignore

_SUPPORT_NEW_UNION = True
except ImportError:
_SUPPORT_NEW_UNION = False
Expand Down
3 changes: 1 addition & 2 deletions tests/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def test_decode_regex_with_flags_from_str() -> None:

# then
assert isinstance(result, Pattern)
assert result.pattern == "\d+"
assert result.pattern == "\\d+"
assert result.flags & re.I
assert result.flags & re.M
assert result.flags & re.S
Expand Down Expand Up @@ -263,7 +263,6 @@ class Tag:
def __init__(self, value: str):
self.value = value


tag = decode({}, Tag)

assert tag.value is None

0 comments on commit 679be73

Please sign in to comment.