Skip to content

Commit

Permalink
Make DefaultDict working with set (#7126)
Browse files Browse the repository at this point in the history
  • Loading branch information
hramezani committed Aug 15, 2023
1 parent 2009d29 commit bcd9c89
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions pydantic/_internal/_std_types_schema.py
Expand Up @@ -444,6 +444,7 @@ def infer_default() -> Callable[[], Any]:
list: list,
typing.Sequence: list,
typing.Set: set,
set: set,
typing.MutableSet: set,
collections.abc.MutableSet: set,
collections.abc.Set: frozenset,
Expand Down
5 changes: 4 additions & 1 deletion tests/test_types.py
Expand Up @@ -4977,12 +4977,15 @@ def test_defaultdict_infer_default_factory() -> None:
class Model(BaseModel):
a: DefaultDict[int, List[int]]
b: DefaultDict[int, int]
c: DefaultDict[int, set]

m = Model(a={}, b={})
m = Model(a={}, b={}, c={})
assert m.a.default_factory is not None
assert m.a.default_factory() == []
assert m.b.default_factory is not None
assert m.b.default_factory() == 0
assert m.c.default_factory is not None
assert m.c.default_factory() == set()


def test_defaultdict_explicit_default_factory() -> None:
Expand Down

0 comments on commit bcd9c89

Please sign in to comment.