12
12
# pylint:disable=R0903
13
13
from abc import ABCMeta
14
14
from collections .abc import Sequence
15
+ from ipaddress import IPv4Address , IPv6Address
15
16
from typing import Optional , Union
16
17
17
18
from geoip2 ._internal import Model
19
+ from geoip2 .types import IPAddress
18
20
19
21
20
22
class Record (Model , metaclass = ABCMeta ):
@@ -841,7 +843,7 @@ class Traits(Record):
841
843
autonomous_system_organization : Optional [str ]
842
844
connection_type : Optional [str ]
843
845
domain : Optional [str ]
844
- _ip_address : Optional [ str ]
846
+ _ip_address : IPAddress
845
847
is_anonymous : bool
846
848
is_anonymous_proxy : bool
847
849
is_anonymous_vpn : bool
@@ -912,6 +914,8 @@ def __init__(
912
914
self .static_ip_score = static_ip_score
913
915
self .user_type = user_type
914
916
self .user_count = user_count
917
+ if ip_address is None :
918
+ raise TypeError ("ip_address must be defined" )
915
919
self ._ip_address = ip_address
916
920
if network is None :
917
921
self ._network = None
@@ -923,12 +927,9 @@ def __init__(
923
927
self ._prefix_len = prefix_len
924
928
925
929
@property
926
- def ip_address (self ):
930
+ def ip_address (self ) -> Union [ IPv4Address , IPv6Address ] :
927
931
"""The IP address for the record."""
928
- if not isinstance (
929
- self ._ip_address ,
930
- (ipaddress .IPv4Address , ipaddress .IPv6Address ),
931
- ):
932
+ if not isinstance (self ._ip_address , (IPv4Address , IPv6Address )):
932
933
self ._ip_address = ipaddress .ip_address (self ._ip_address )
933
934
return self ._ip_address
934
935
0 commit comments