Skip to content

Commit

Permalink
fix: protect default value for serialization_types from unintended …
Browse files Browse the repository at this point in the history
…downstream modifications (#30)

Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
jkowalleck authored Oct 6, 2023
1 parent 4eddb24 commit 0e814f5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions serializable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ class SerializationType(str, enum.Enum):
XML = 'XML'


_DEFAULT_SERIALIZATION_TYPES = [SerializationType.JSON, SerializationType.XML]
# tuple = immutable collection -> immutable = prevent unexpected modifications
_DEFAULT_SERIALIZATION_TYPES: Iterable[SerializationType] = (
SerializationType.JSON,
SerializationType.XML,
)


@enum.unique
Expand Down Expand Up @@ -638,7 +642,7 @@ def __init__(self, *, klass: Any, custom_name: Optional[str] = None,
if serialization_types is None:
serialization_types = _DEFAULT_SERIALIZATION_TYPES
self._serialization_types = serialization_types
self._ignore_during_deserialization = set(ignore_during_deserialization or {})
self._ignore_during_deserialization = set(ignore_during_deserialization or [])

@property
def name(self) -> str:
Expand Down Expand Up @@ -1109,7 +1113,7 @@ def serializable_class(cls: Optional[Any] = None, *, name: Optional[str] = None,

def decorate(kls: Type[_T]) -> Type[_T]:
ObjectMetadataLibrary.register_klass(
klass=kls, custom_name=name, serialization_types=serialization_types or {},
klass=kls, custom_name=name, serialization_types=serialization_types or [],
ignore_during_deserialization=ignore_during_deserialization
)
return kls
Expand Down

0 comments on commit 0e814f5

Please sign in to comment.