From 36a7f6d8d8c31a39383e0e584b98e3fcd7a47284 Mon Sep 17 00:00:00 2001 From: Christian Ledermann Date: Thu, 18 Jul 2024 20:23:25 +0100 Subject: [PATCH] make __eq__ generic --- fastkml/atom.py | 54 ------------------------------- fastkml/base.py | 2 +- fastkml/kml_base.py | 24 -------------- pyproject.toml | 1 + tests/geometries/geometry_test.py | 1 - 5 files changed, 2 insertions(+), 80 deletions(-) diff --git a/fastkml/atom.py b/fastkml/atom.py index 592d667f..7624b7c4 100644 --- a/fastkml/atom.py +++ b/fastkml/atom.py @@ -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, @@ -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, diff --git a/fastkml/base.py b/fastkml/base.py index 0ea21c07..69e4fed6 100644 --- a/fastkml/base.py +++ b/fastkml/base.py @@ -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, diff --git a/fastkml/kml_base.py b/fastkml/kml_base.py index fd11c1a1..b454a583 100644 --- a/fastkml/kml_base.py +++ b/fastkml/kml_base.py @@ -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, diff --git a/pyproject.toml b/pyproject.toml index 9cc02420..f194d40b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -255,6 +255,7 @@ select = [ "D101", "D102", "D103", + "D104", "PLR2004", "S101", "SLF001", diff --git a/tests/geometries/geometry_test.py b/tests/geometries/geometry_test.py index b6a42f15..0d47a3f5 100644 --- a/tests/geometries/geometry_test.py +++ b/tests/geometries/geometry_test.py @@ -330,7 +330,6 @@ def test_to_string_with_args(self) -> None: assert "extrude>1relativeToGround<" 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."""