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

Add remaining type hints to synapse.events. #11098

Merged
merged 20 commits into from
Nov 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class DictProperty:
def __init__(self, key: str):
self.key = key

def __get__(self, instance, owner=None):
def __get__(
self,
instance: Optional[Union["_EventInternalMetadata", "EventBase"]],
owner: Optional[Type[Union["_EventInternalMetadata", "EventBase"]]] = None,
clokep marked this conversation as resolved.
Show resolved Hide resolved
) -> Any:
# if the property is accessed as a class property rather than an instance
# property, return the property itself rather than the value
if instance is None:
Expand All @@ -65,10 +69,12 @@ def __get__(self, instance, owner=None):
"'%s' has no '%s' property" % (type(instance), self.key)
) from e1.__context__

def __set__(self, instance, v):
def __set__(
self, instance: Union["_EventInternalMetadata", "EventBase"], v: Any
) -> None:
instance._dict[self.key] = v

def __delete__(self, instance):
def __delete__(self, instance: Any) -> None:
clokep marked this conversation as resolved.
Show resolved Hide resolved
try:
del instance._dict[self.key]
except KeyError as e1:
Expand All @@ -90,7 +96,11 @@ def __init__(self, key: str, default: Any):
super().__init__(key)
self.default = default

def __get__(self, instance, owner=None):
def __get__(
self,
instance: Optional[Union["_EventInternalMetadata", "EventBase"]],
owner: Optional[Type[Union["_EventInternalMetadata", "EventBase"]]] = None,
) -> Any:
if instance is None:
return self
return instance._dict.get(self.key, self.default)
Expand Down Expand Up @@ -243,7 +253,7 @@ def __init__(
redacts: Optional[str] = DefaultDictProperty("redacts", None) # type: ignore[assignment]
room_id: str = DictProperty("room_id") # type: ignore[assignment]
sender: str = DictProperty("sender") # type: ignore[assignment]
state_key = DictProperty("state_key") # type: ignore[assignment]
state_key: str = DictProperty("state_key") # type: ignore[assignment]
clokep marked this conversation as resolved.
Show resolved Hide resolved
type: str = DictProperty("type") # type: ignore[assignment]
user_id: str = DictProperty("sender") # type: ignore[assignment]

Expand Down