Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3102 from NotAFile/py3-attributeerror
Browse files Browse the repository at this point in the history
Make event properties raise AttributeError instead
  • Loading branch information
richvdh authored Apr 30, 2018
2 parents 950a32e + 0c9db26 commit 01e8a52
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,26 @@ def get_send_on_behalf_of(self):


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,
Expand Down

0 comments on commit 01e8a52

Please sign in to comment.