Skip to content
Snippets Groups Projects
Commit 83231771 authored by Rajmund Hruška's avatar Rajmund Hruška
Browse files

Restrict objects for testing equality

parent 7e4d41e8
Branches
No related tags found
1 merge request!9Add equality with arbitrary objects
Pipeline #12424 passed
...@@ -26,8 +26,15 @@ class Range(object): ...@@ -26,8 +26,15 @@ class Range(object):
return self.high() - self.low() + 1 return self.high() - self.low() + 1
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, (IPRangeBase, IPNetBase, IPAddrBase)): if (
return (self.low() == other.low() and self.high() == other.high()) hasattr(self, "single")
and hasattr(other, "single")
and (
issubclass(self.single, other.single)
or issubclass(self.single, other.single)
)
):
return self.low() == other.low() and self.high() == other.high()
return False return False
def __ne__(self, other): def __ne__(self, other):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment