Skip to content

Commit

Permalink
Fix to tidy up some logic in IsIp
Browse files Browse the repository at this point in the history
  • Loading branch information
osintalex committed Jun 25, 2022
1 parent bf9e130 commit 004bf82
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions dirty_equals/_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,13 @@ def equals(self, other: Any) -> bool:
else:
return False

return self.run_kwargs_checks(ip)

def run_kwargs_checks(self, ip: Union[IPv4Network, IPv6Network]) -> bool:

if self.version and not self.netmask:
return self.version == ip.version

if self.version and self.netmask:
version_check = self.version == ip.version
address_format = {4: IPv4Address, 6: IPv6Address}[self.version]
netmask_check = int(address_format(self.netmask)) == int(ip.netmask)
return version_check and netmask_check
if self.version:
if self.netmask:
version_check = self.version == ip.version
address_format = {4: IPv4Address, 6: IPv6Address}[self.version]
netmask_check = int(address_format(self.netmask)) == int(ip.netmask)
return version_check and netmask_check
elif self.version != ip.version:
return False

return True

0 comments on commit 004bf82

Please sign in to comment.