From e5afd0ab99847f3d3083d4522243f1c717c93ba0 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 21 Mar 2023 22:23:08 +0000 Subject: Make event objects unhashable Generally speaking one should look up an event by its id. Otherwise we'll fall back to `object.__hash__` (the instance's address, under CPython) which is probably not what you want. Noticed in #15240. --- synapse/events/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py index 91118a8d84..d3cec6412a 100644 --- a/synapse/events/__init__.py +++ b/synapse/events/__init__.py @@ -24,6 +24,7 @@ from typing import ( Generic, Iterable, List, + NoReturn, Optional, Sequence, Tuple, @@ -338,6 +339,9 @@ class EventBase(metaclass=abc.ABCMeta): type: DictProperty[str] = DictProperty("type") user_id: DictProperty[str] = DictProperty("sender") + def __hash__(self) -> NoReturn: + raise NotImplementedError() + @property def event_id(self) -> str: raise NotImplementedError() -- cgit 1.4.1