summary refs log tree commit diff
path: root/synapse/events/__init__.py
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2018-04-30 09:22:09 +0100
committerGitHub <noreply@github.com>2018-04-30 09:22:09 +0100
commit01e8a528257e10207c25682debe439b22cbae316 (patch)
tree82a8a2a81e27786336a6ac1b1b158210332f11c0 /synapse/events/__init__.py
parentMerge pull request #3152 from NotAFile/py3-local-imports (diff)
parentadd comment explaining attributeerror (diff)
downloadsynapse-01e8a528257e10207c25682debe439b22cbae316.tar.xz
Merge pull request #3102 from NotAFile/py3-attributeerror
Make event properties raise AttributeError instead
Diffstat (limited to 'synapse/events/__init__.py')
-rw-r--r--synapse/events/__init__.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py
index e673e96cc0..c3ff85c49a 100644
--- a/synapse/events/__init__.py
+++ b/synapse/events/__init__.py
@@ -47,14 +47,26 @@ class _EventInternalMetadata(object):
 
 
 def _event_dict_property(key):
+    # We want to be able to use hasattr with the event dict properties.
+    # However, (on python3) hasattr expects AttributeError to be raised. Hence,
+    # we need to transform the KeyError into an AttributeError
     def getter(self):
-        return self._event_dict[key]
+        try:
+            return self._event_dict[key]
+        except KeyError:
+            raise AttributeError(key)
 
     def setter(self, v):
-        self._event_dict[key] = v
+        try:
+            self._event_dict[key] = v
+        except KeyError:
+            raise AttributeError(key)
 
     def delete(self):
-        del self._event_dict[key]
+        try:
+            del self._event_dict[key]
+        except KeyError:
+            raise AttributeError(key)
 
     return property(
         getter,