Skip to content

Commit 28c3b12

Browse files
committed
Allow Traits ip_address to be None again
1 parent 056787f commit 28c3b12

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

HISTORY.rst

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
History
55
-------
66

7+
5.0.1 (2025-01-28)
8+
++++++++++++++++++
9+
10+
* Allow ``ip_address`` in the ``Traits`` record to be ``None`` again. The
11+
primary use case for this is from the ``minfraud`` package.
12+
713
5.0.0 (2025-01-28)
814
++++++++++++++++++
915

geoip2/records.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ class Traits(Record):
843843
autonomous_system_organization: Optional[str]
844844
connection_type: Optional[str]
845845
domain: Optional[str]
846-
_ip_address: IPAddress
846+
_ip_address: Optional[IPAddress]
847847
is_anonymous: bool
848848
is_anonymous_proxy: bool
849849
is_anonymous_vpn: bool
@@ -914,8 +914,6 @@ def __init__(
914914
self.static_ip_score = static_ip_score
915915
self.user_type = user_type
916916
self.user_count = user_count
917-
if ip_address is None:
918-
raise TypeError("ip_address must be defined")
919917
self._ip_address = ip_address
920918
if network is None:
921919
self._network = None
@@ -927,11 +925,16 @@ def __init__(
927925
self._prefix_len = prefix_len
928926

929927
@property
930-
def ip_address(self) -> Union[IPv4Address, IPv6Address]:
928+
def ip_address(self) -> Optional[Union[IPv4Address, IPv6Address]]:
931929
"""The IP address for the record."""
932-
if not isinstance(self._ip_address, (IPv4Address, IPv6Address)):
933-
self._ip_address = ipaddress.ip_address(self._ip_address)
934-
return self._ip_address
930+
ip_address = self._ip_address
931+
if ip_address is None:
932+
return None
933+
934+
if not isinstance(ip_address, (IPv4Address, IPv6Address)):
935+
ip_address = ipaddress.ip_address(ip_address)
936+
self._ip_address = ip_address
937+
return ip_address
935938

936939
@property
937940
def network(self) -> Optional[Union[ipaddress.IPv4Network, ipaddress.IPv6Network]]:

0 commit comments

Comments
 (0)