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
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def __init__(

auth_events = DictProperty("auth_events") # type: ignore[assignment]
depth: int = DictProperty("depth") # type: ignore[assignment]
content = DictProperty("content") # type: ignore[assignment]
content: JsonDict = DictProperty("content") # type: ignore[assignment]
hashes: Dict[str, str] = DictProperty("hashes") # type: ignore[assignment]
origin: str = DictProperty("origin") # type: ignore[assignment]
origin_server_ts: int = DictProperty("origin_server_ts") # type: ignore[assignment]
Expand Down
10 changes: 6 additions & 4 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,11 +1504,13 @@ async def persist_and_notify_client_event(
next_batch_id = event.content.get(
EventContentFields.MSC2716_NEXT_BATCH_ID
)
conflicting_insertion_event_id = (
await self.store.get_insertion_event_by_batch_id(
event.room_id, next_batch_id
conflicting_insertion_event_id = None
if next_batch_id:
clokep marked this conversation as resolved.
Show resolved Hide resolved
conflicting_insertion_event_id = (
await self.store.get_insertion_event_by_batch_id(
event.room_id, next_batch_id
)
)
)
if conflicting_insertion_event_id is not None:
# The current insertion event that we're processing is invalid
# because an insertion event already exists in the room with the
Expand Down
4 changes: 3 additions & 1 deletion synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ async def action_for_event_by_user(
# that user, as they might not be already joined.
if event.type == EventTypes.Member and event.state_key == uid:
display_name = event.content.get("displayname", None)
if not isinstance(display_name, str):
display_name = None

if count_as_unread:
# Add an element for the current user if the event needs to be marked as
Expand Down Expand Up @@ -268,7 +270,7 @@ def _condition_checker(
evaluator: PushRuleEvaluatorForEvent,
conditions: List[dict],
uid: str,
display_name: str,
display_name: Optional[str],
cache: Dict[str, bool],
) -> bool:
for cond in conditions:
Expand Down
4 changes: 2 additions & 2 deletions synapse/push/push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def __init__(
self._value_cache = _flatten_dict(event)

def matches(
self, condition: Dict[str, Any], user_id: str, display_name: str
self, condition: Dict[str, Any], user_id: str, display_name: Optional[str]
) -> bool:
if condition["kind"] == "event_match":
return self._event_match(condition, user_id)
Expand Down Expand Up @@ -172,7 +172,7 @@ def _event_match(self, condition: dict, user_id: str) -> bool:

return _glob_matches(pattern, haystack)

def _contains_display_name(self, display_name: str) -> bool:
def _contains_display_name(self, display_name: Optional[str]) -> bool:
if not display_name:
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
return False

Expand Down
8 changes: 5 additions & 3 deletions synapse/storage/databases/main/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ async def get_users_who_share_room_with_user(

async def get_joined_users_from_context(
self, event: EventBase, context: EventContext
):
) -> Dict[str, ProfileInfo]:
state_group = context.state_group
if not state_group:
# If state_group is None it means it has yet to be assigned a
Expand All @@ -583,7 +583,9 @@ async def get_joined_users_from_context(
event.room_id, state_group, current_state_ids, event=event, context=context
)

async def get_joined_users_from_state(self, room_id, state_entry):
async def get_joined_users_from_state(
self, room_id, state_entry
) -> Dict[str, ProfileInfo]:
state_group = state_entry.state_group
if not state_group:
# If state_group is None it means it has yet to be assigned a
Expand All @@ -606,7 +608,7 @@ async def _get_joined_users_from_context(
cache_context,
event=None,
context=None,
):
) -> Dict[str, ProfileInfo]:
# We don't use `state_group`, it's there so that we can cache based
# on it. However, it's important that it's never None, since two current_states
# with a state_group of None are likely to be different.
Expand Down