Skip to content

Commit d9c19c1

Browse files
authored
Merge pull request #438 from acolley-gel/main
Fix frozenset union with prim #437
2 parents fead102 + 44274ce commit d9c19c1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

serde/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def is_list_instance(obj: Any, typ: Type[Any]) -> bool:
413413

414414

415415
def is_set_instance(obj: Any, typ: Type[Any]) -> bool:
416-
if not isinstance(obj, set):
416+
if not isinstance(obj, (set, frozenset)):
417417
return False
418418
if len(obj) == 0 or is_bare_set(typ):
419419
return True

tests/test_union.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
from dataclasses import dataclass
44
from ipaddress import IPv4Address
5-
from typing import Dict, Generic, List, NewType, Optional, Tuple, TypeVar, Union
5+
from typing import Dict, FrozenSet, Generic, List, NewType, Optional, Tuple, TypeVar, Union
66
from uuid import UUID
77

88
import pytest
@@ -763,3 +763,12 @@ class Bar:
763763
# untagged tagged
764764
s = to_json(bar, cls=Untagged(Union[Foo, Bar]))
765765
assert bar == from_json(Untagged(Union[Foo, Bar]), s)
766+
767+
768+
def test_union_frozenset_with_prim():
769+
@serde
770+
@dataclass
771+
class Foo:
772+
a: Union[FrozenSet[int], int]
773+
774+
assert to_dict(Foo(frozenset({1}))) == {"a": {1}}

0 commit comments

Comments
 (0)