Skip to content

Commit

Permalink
Fix regression settings.serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo committed Nov 6, 2020
1 parent 07cced9 commit 6dbd785
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions apischema/conversions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
__all__ = [
"Deserialization",
"Conversions",
"Serialization",
"deserializer",
"extra_deserializer",
"extra_serializer",
Expand All @@ -19,3 +22,5 @@
serializer,
)
from .raw import raw_deserializer
from .utils import Conversions
from .visitor import Deserialization, Serialization
12 changes: 4 additions & 8 deletions apischema/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass, is_dataclass
from enum import Enum
from functools import partial
from types import MappingProxyType
from typing import Any, Callable, Collection, Mapping, Sequence, Tuple, Type

from apischema.cache import cache
Expand All @@ -13,12 +12,12 @@
from apischema.dataclass_utils import get_alias
from apischema.fields import FIELDS_SET_ATTR, fields_set
from apischema.metadata.keys import check_metadata, is_aggregate_field
from apischema.types import PRIMITIVE_TYPES
from apischema.types import COLLECTION_TYPES, MAPPING_TYPES, PRIMITIVE_TYPES
from apischema.visitor import Unsupported, dataclass_types_and_fields

PRIMITIVE_TYPES_SET = set(PRIMITIVE_TYPES)
COLLECTION_TYPE_SET = {list, tuple, set, frozenset}
MAPPING_TYPE_SET = {dict, MappingProxyType}
COLLECTION_TYPE_SET = set(COLLECTION_TYPES.values())
MAPPING_TYPE_SET = set(MAPPING_TYPES.values())


try:
Expand Down Expand Up @@ -78,9 +77,6 @@ def method(obj: Any, *, exclude_unset: bool) -> Any:
return normal_fields, aggregate_fields


is_conversion = SerializationVisitor.is_conversion


def serialize(
obj: Any, *, conversions: Conversions = None, exclude_unset: bool = True
) -> Any:
Expand All @@ -99,7 +95,7 @@ def serialize(
): serialize(value, conversions=conversions, exclude_unset=exclude_unset)
for key, value in obj.items()
}
conversion = is_conversion(cls, conversions)
conversion = SerializationVisitor.is_conversion(cls, conversions)
if conversion is not None:
_, (converter, sub_conversions) = conversion
# TODO Maybe add exclude_unset parameter to serializers
Expand Down

0 comments on commit 6dbd785

Please sign in to comment.