Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DefaultDict working with set #7126

Merged
merged 1 commit into from Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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