Skip to content

Add ipaddress types to Schema.TYPE_MAPPING#2906

Open
dhruvildarji wants to merge 1 commit intomarshmallow-code:devfrom
dhruvildarji:fix/ip-type-mapping
Open

Add ipaddress types to Schema.TYPE_MAPPING#2906
dhruvildarji wants to merge 1 commit intomarshmallow-code:devfrom
dhruvildarji:fix/ip-type-mapping

Conversation

@dhruvildarji
Copy link

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>
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

1 participant