Skip to content

Commit 100dad9

Browse files
committed
improve error messages for invalid objects
1 parent a0d7181 commit 100dad9

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Lib/ipaddress.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ def __contains__(self, other):
737737
def overlaps(self, other):
738738
"""Tell if self is partly contained in other."""
739739
if not isinstance(other, _BaseNetwork):
740-
raise TypeError("%s is not a network object" % other)
740+
raise TypeError(f"expecting a network object, not {type(other)}")
741741
return self.network_address in other or (
742742
self.broadcast_address in other or (
743743
other.network_address in self or (
@@ -818,7 +818,7 @@ def address_exclude(self, other):
818818
819819
"""
820820
if not isinstance(other, _BaseNetwork):
821-
raise TypeError("%s is not a network object" % other)
821+
raise TypeError(f"expecting a network object, not {type(other)}")
822822
_check_ip_version(self, other)
823823
if not other.subnet_of(self):
824824
raise ValueError('%s not contained in %s' % (other, self))
@@ -885,7 +885,7 @@ def compare_networks(self, other):
885885
886886
"""
887887
if not isinstance(other, _BaseNetwork):
888-
raise TypeError("%s is not a network object" % other)
888+
raise TypeError(f"expecting a network object, not {type(other)}")
889889
_check_ip_version(self, other)
890890
# self.version == other.version below here:
891891
if self.network_address < other.network_address:
@@ -1025,13 +1025,13 @@ def _is_subnet_of(a, b):
10251025
def subnet_of(self, other):
10261026
"""Return True if this network is a subnet of other."""
10271027
if not isinstance(other, _BaseNetwork):
1028-
raise TypeError(f"{other} is not a network object")
1028+
raise TypeError(f"expecting a network object, not {type(other)}")
10291029
return self._is_subnet_of(self, other)
10301030

10311031
def supernet_of(self, other):
10321032
"""Return True if this network is a supernet of other."""
10331033
if not isinstance(other, _BaseNetwork):
1034-
raise TypeError(f"{other} is not a network object")
1034+
raise TypeError(f"expecting a network object, not {type(other)}")
10351035
return self._is_subnet_of(other, self)
10361036

10371037
@property

0 commit comments

Comments
 (0)