Skip to content

Commit

Permalink
Remove need to be serialisable when insntantiating encoder or decoder…
Browse files Browse the repository at this point in the history
… explicitly in the code
  • Loading branch information
dkraczkowski committed Nov 7, 2023
1 parent 5191bab commit 20ea4d3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 12 deletions.
2 changes: 1 addition & 1 deletion chili/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def build_type_decoder(a_type: Type, extra_decoders: TypeDecoders = None, module
return TypedDictDecoder(origin_type, extra_decoders)

if is_class(origin_type) and is_user_string(origin_type):
return ProxyDecoder[origin_type](origin_type)
return ProxyDecoder[origin_type](origin_type) # type: ignore

if origin_type is Union:
type_args = get_type_args(a_type)
Expand Down
1 change: 1 addition & 0 deletions chili/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def is_typed_dict(type_name: Type) -> bool:
def is_user_string(type_name: Type) -> bool:
return issubclass(type_name, UserString)


def map_generic_type(type_name: Any, type_map: Dict[Any, Any]) -> Any:
if not type_map:
return type_name
Expand Down
11 changes: 0 additions & 11 deletions tests/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,3 @@ class Example:
# then
assert isinstance(instance, Decoder)
assert instance.__generic__ == Example


def test_fail_encode_non_encodable_type() -> None:
# given
class Example:
name: str
age: int

# when
with pytest.raises(DecoderError.invalid_type):
Decoder[Example]()
1 change: 1 addition & 0 deletions tests/usecases/userstring_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_can_decode_userstring() -> None:
# given
class ComplexString(UserString):
pass

string = "Example String"

# when
Expand Down

0 comments on commit 20ea4d3

Please sign in to comment.