Skip to content

Commit

Permalink
Allow Traits ip_address to be None again
Browse files Browse the repository at this point in the history
  • Loading branch information
oschwald committed Jan 28, 2025
1 parent 056787f commit 3ea807c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
History
-------

5.0.1 (2025-01-28)
++++++++++++++++++

* Allow ``ip_address`` in the ``Traits`` record to be ``None`` again. The
primary use case for this is from the ``minfraud`` package.

5.0.0 (2025-01-28)
++++++++++++++++++

Expand Down
16 changes: 9 additions & 7 deletions geoip2/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ class Traits(Record):
autonomous_system_organization: Optional[str]
connection_type: Optional[str]
domain: Optional[str]
_ip_address: IPAddress
_ip_address: Optional[IPAddress]
is_anonymous: bool
is_anonymous_proxy: bool
is_anonymous_vpn: bool
Expand Down Expand Up @@ -914,8 +914,6 @@ def __init__(
self.static_ip_score = static_ip_score
self.user_type = user_type
self.user_count = user_count
if ip_address is None:
raise TypeError("ip_address must be defined")
self._ip_address = ip_address
if network is None:
self._network = None
Expand All @@ -927,11 +925,15 @@ def __init__(
self._prefix_len = prefix_len

@property
def ip_address(self) -> Union[IPv4Address, IPv6Address]:
def ip_address(self) -> Optional[Union[IPv4Address, IPv6Address]]:
"""The IP address for the record."""
if not isinstance(self._ip_address, (IPv4Address, IPv6Address)):
self._ip_address = ipaddress.ip_address(self._ip_address)
return self._ip_address
ip_address = self._ip_address
if ip_address is None:
return None

if not isinstance(ip_address, (IPv4Address, IPv6Address)):
self._ip_address = ipaddress.ip_address(ip_address)
return ip_address

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

0 comments on commit 3ea807c

Please sign in to comment.