Issue 14814: Correctly return NotImplemented from ipaddress._BaseNetwork.__eq__

This commit is contained in:
Nick Coghlan 2012-07-07 23:05:59 +10:00
parent d46f7d209b
commit 9a9c28ce7a
3 changed files with 25 additions and 7 deletions

View file

@ -651,12 +651,12 @@ class _BaseNetwork(_IPAddressBase):
return not lt
def __eq__(self, other):
if not isinstance(other, _BaseNetwork):
raise TypeError('%s and %s are not of the same type' % (
self, other))
return (self._version == other._version and
self.network_address == other.network_address and
int(self.netmask) == int(other.netmask))
try:
return (self._version == other._version and
self.network_address == other.network_address and
int(self.netmask) == int(other.netmask))
except AttributeError:
return NotImplemented
def __ne__(self, other):
eq = self.__eq__(other)