Feature/eq method for default (#1789)

* Add changelog for #1707

* Add __eq__ and __hash__ methods to the Default class

* Add tests for the eq and hash methods to the TestDefault
This commit is contained in:
Aleksandr Zainulgabidinov 2026-04-04 01:24:34 +03:00 committed by GitHub
parent 9f49c0413f
commit 875f37f780
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 0 deletions

1
CHANGES/1707.feature.rst Normal file
View file

@ -0,0 +1 @@
Added `__eq__` and `__hash__` methods to the `Default` class.

View file

@ -28,6 +28,14 @@ class Default:
def __repr__(self) -> str:
return f"<{self}>"
def __eq__(self, other: object) -> bool:
if not isinstance(other, Default):
return NotImplemented
return self._name == other._name
def __hash__(self) -> int:
return hash(self._name)
@dataclass(**dataclass_kwargs(slots=True, kw_only=True))
class DefaultBotProperties:

View file

@ -24,6 +24,15 @@ class TestDefault:
default = Default("test")
assert repr(default) == "<Default('test')>"
def test_eq_same_name(self):
assert Default("test") == Default("test")
def test_eq_different_name(self):
assert Default("foo") != Default("bar")
def test_hash(self):
assert hash(Default("test")) == hash(Default("test"))
class TestDefaultBotProperties:
def test_post_init_empty(self):