Skip to content

Add ipaddress types to Schema.TYPE_MAPPING#2906

Merged
sloria merged 4 commits intomarshmallow-code:devfrom
dhruvildarji:fix/ip-type-mapping
Mar 25, 2026
Merged

Add ipaddress types to Schema.TYPE_MAPPING#2906
sloria merged 4 commits intomarshmallow-code:devfrom
dhruvildarji:fix/ip-type-mapping

Conversation

@dhruvildarji
Copy link
Copy Markdown
Contributor

Summary

Closes #1695.

Adds mappings from Python's ipaddress types to their corresponding marshmallow field classes in Schema.TYPE_MAPPING:

Python type Marshmallow field
ipaddress.IPv4Address fields.IPv4
ipaddress.IPv6Address fields.IPv6
ipaddress.IPv4Interface fields.IPv4Interface
ipaddress.IPv6Interface fields.IPv6Interface

This enables libraries like marshmallow_dataclass to automatically resolve these types from annotations.

Note: The generic IP and IPInterface fields are intentionally excluded since there is no single Python type that maps to them. IPv4Network/IPv6Network are also excluded since marshmallow does not have corresponding network field classes.

Test plan

  • Added parametrized tests in TestIPTypeMappings verifying all 4 new type mappings
  • All 1136 existing tests pass

Map ipaddress.IPv4Address, IPv6Address, IPv4Interface, and
IPv6Interface to their corresponding marshmallow field classes
in Schema.TYPE_MAPPING, enabling automatic field resolution
for libraries like marshmallow_dataclass.

Closes marshmallow-code#1695

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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

@sloria sloria merged commit c38b48e into marshmallow-code:dev Mar 25, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add type mapping from IP* fields to ipaddress

2 participants