From 7c6fa1374fd1ada3bef40f528535600b7bb46b2b Mon Sep 17 00:00:00 2001 From: Richard Nemeth Date: Thu, 17 Jul 2025 18:23:21 +0200 Subject: [PATCH] fix: implement hash --- src/keycloak/authorization/role.py | 9 +++++++++ tests/test_authorization.py | 1 + 2 files changed, 10 insertions(+) diff --git a/src/keycloak/authorization/role.py b/src/keycloak/authorization/role.py index 0ffb193..7d01f77 100644 --- a/src/keycloak/authorization/role.py +++ b/src/keycloak/authorization/role.py @@ -78,3 +78,12 @@ class Role: msg = f"Cannot compare Role with {type(other)}" raise NotImplementedError(msg) + + def __hash__(self) -> int: + """ + Hash method. + + :returns: Hash value + :rtype: int + """ + return hash(f"{self.name}-{self.required}") diff --git a/tests/test_authorization.py b/tests/test_authorization.py index 2ceb622..bc30f8f 100644 --- a/tests/test_authorization.py +++ b/tests/test_authorization.py @@ -40,6 +40,7 @@ def test_authorization_objects() -> None: assert not r.required assert r.get_name() == "test" assert r == r # noqa: PLR0124 + assert hash(r) == hash("test-False") assert r == "test" with pytest.raises(NotImplementedError) as err: