Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/marshmallow/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import decimal
import functools
import inspect
import ipaddress
import json
import operator
import typing
Expand Down Expand Up @@ -290,6 +291,10 @@ class AlbumSchema(Schema):
dt.date: ma_fields.Date,
dt.timedelta: ma_fields.TimeDelta,
decimal.Decimal: ma_fields.Decimal,
ipaddress.IPv4Address: ma_fields.IPv4,
ipaddress.IPv6Address: ma_fields.IPv6,
ipaddress.IPv4Interface: ma_fields.IPv4Interface,
ipaddress.IPv6Interface: ma_fields.IPv6Interface,
}
#: Overrides for default schema-level error messages
error_messages: dict[str, str] = {}
Expand Down
15 changes: 15 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime as dt
import ipaddress
import math
import random
from collections import OrderedDict
Expand Down Expand Up @@ -2549,3 +2550,17 @@ class MySchema(Schema):
result = MySchema().dump({"foo": "bar"})
assert result == {"foo": "bar"}
assert isinstance(result, dict_cls)


class TestIPTypeMappings:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test feels gratuitous because it's just testing the implementation. i'll remove for now

@pytest.mark.parametrize(
("ip_type", "expected_field_cls"),
[
(ipaddress.IPv4Address, fields.IPv4),
(ipaddress.IPv6Address, fields.IPv6),
(ipaddress.IPv4Interface, fields.IPv4Interface),
(ipaddress.IPv6Interface, fields.IPv6Interface),
],
)
def test_ip_types_in_type_mapping(self, ip_type, expected_field_cls):
assert Schema.TYPE_MAPPING[ip_type] is expected_field_cls