Skip to content

Commit

Permalink
make __eq__ generic
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Jul 18, 2024
1 parent 9e954cf commit 36a7f6d
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 80 deletions.
54 changes: 0 additions & 54 deletions fastkml/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,35 +177,6 @@ def __bool__(self) -> bool:
"""
return bool(self.href)

def __eq__(self, other: object) -> bool:
"""
Check if the Link object is equal to another object.
Parameters
----------
other : object
The object to compare with.
Returns
-------
bool
True if the Link object is equal to the other object, False otherwise.
"""
try:
assert isinstance(other, type(self)) # noqa: S101
except AssertionError:
return False
return (
super().__eq__(other)
and self.href == other.href
and self.rel == other.rel
and self.type == other.type
and self.hreflang == other.hreflang
and self.title == other.title
and self.length == other.length
)


registry.register(
Link,
Expand Down Expand Up @@ -350,31 +321,6 @@ def __bool__(self) -> bool:
"""
return bool(self.name)

def __eq__(self, other: object) -> bool:
"""
Check if the _Person object is equal to another object.
Args:
----
other (object): The object to compare with.
Returns:
-------
bool: True if the _Person object is equal to the other object,
False otherwise.
"""
try:
assert isinstance(other, type(self)) # noqa: S101
except AssertionError:
return False
return (
super().__eq__(other)
and self.name == other.name
and self.uri == other.uri
and self.email == other.email
)


registry.register(
_Person,
Expand Down
2 changes: 1 addition & 1 deletion fastkml/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __eq__(self, other: object) -> bool:
if type(self) is not type(other):
return False
assert isinstance(other, type(self)) # noqa: S101
return self.ns == other.ns and self.name_spaces == other.name_spaces
return self.__dict__ == other.__dict__

def etree_element(
self,
Expand Down
24 changes: 0 additions & 24 deletions fastkml/kml_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,6 @@ def __repr__(self) -> str:
")"
)

def __eq__(self, other: object) -> bool:
"""
Return True if the two objects are equal.
Parameters
----------
other: (object)
The object to compare with.
Returns
-------
bool: True if the two objects are equal, False otherwise.
"""
try:
assert isinstance(other, type(self)) # noqa: S101
return (
super().__eq__(other)
and self.id == other.id
and self.target_id == other.target_id
)
except AssertionError:
return False


registry.register(
_BaseObject,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ select = [
"D101",
"D102",
"D103",
"D104",
"PLR2004",
"S101",
"SLF001",
Expand Down
1 change: 0 additions & 1 deletion tests/geometries/geometry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ def test_to_string_with_args(self) -> None:
assert "extrude>1</" in g.to_string()
assert "altitudeMode>relativeToGround<" in g.to_string()
assert "tessellate>1<" in g.to_string()
# assert not g.to_string()

def test_from_string(self) -> None:
"""Test the from_string method."""
Expand Down

0 comments on commit 36a7f6d

Please sign in to comment.