auth.Auth: Add methods __eq__() and .__hash__()
Entity instances are compared by identity. The forge clients create a fresh Owner object on every lookup, so two objects denoting the same user are never equal, and equality-based matching - permission checks, caches keyed on the entity - does not work. Give Entity value equality: two entities are equal when they carry the same kind and the same name. __hash__() is derived from the same fields, so entities remain usable as dict keys and in sets. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.6.0 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
226ae4901c
commit
819d6283bd
1 changed files with 11 additions and 1 deletions
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
import abc
|
||||
|
||||
from enum import Enum, Flag, auto
|
||||
from typing import TYPE_CHECKING, Any, Self, Sequence, TypeAlias, cast
|
||||
from typing import TYPE_CHECKING, Any, Self, Sequence, TypeAlias, cast, override
|
||||
|
||||
from ..Config import Config
|
||||
from ..enum_helper import kebab_to_pascal
|
||||
|
|
@ -32,6 +32,16 @@ class Kind(Flag):
|
|||
|
||||
class Entity(abc.ABC): # export
|
||||
|
||||
@override
|
||||
def __eq__(self, other: Any) -> bool:
|
||||
if not isinstance(other, Entity):
|
||||
return NotImplemented
|
||||
return (self.kind, self.name) == (other.kind, other.name)
|
||||
|
||||
@override
|
||||
def __hash__(self) -> int:
|
||||
return hash((self.kind, self.name))
|
||||
|
||||
@abc.abstractmethod
|
||||
def _kind(self) -> Kind:
|
||||
...
|
||||
|
|
|
|||
Loading…
Reference in a new issue