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

Commit e0f11ae

Browse files
author
David Robertson
authored
disallow-untyped-defs for synapse.push (#11023)
1 parent 5e29d41 commit e0f11ae

File tree

7 files changed

+28
-10
lines changed

7 files changed

+28
-10
lines changed

changelog.d/11023.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add additional type hints for `synapse.push`.

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ files =
9696
[mypy-synapse.handlers.*]
9797
disallow_untyped_defs = True
9898

99+
[mypy-synapse.push.*]
100+
disallow_untyped_defs = True
101+
99102
[mypy-synapse.rest.*]
100103
disallow_untyped_defs = True
101104

synapse/push/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def on_new_notifications(self, max_token: RoomStreamToken) -> None:
9494
self._start_processing()
9595

9696
@abc.abstractmethod
97-
def _start_processing(self):
97+
def _start_processing(self) -> None:
9898
"""Start processing push notifications."""
9999
raise NotImplementedError()
100100

synapse/push/bulk_push_rule_evaluator.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ def _condition_checker(
290290
return True
291291

292292

293+
MemberMap = Dict[str, Tuple[str, str]]
294+
Rule = Dict[str, dict]
295+
RulesByUser = Dict[str, List[Rule]]
296+
StateGroup = Union[object, int]
297+
298+
293299
@attr.s(slots=True)
294300
class RulesForRoomData:
295301
"""The data stored in the cache by `RulesForRoom`.
@@ -299,16 +305,16 @@ class RulesForRoomData:
299305
"""
300306

301307
# event_id -> (user_id, state)
302-
member_map = attr.ib(type=Dict[str, Tuple[str, str]], factory=dict)
308+
member_map = attr.ib(type=MemberMap, factory=dict)
303309
# user_id -> rules
304-
rules_by_user = attr.ib(type=Dict[str, List[Dict[str, dict]]], factory=dict)
310+
rules_by_user = attr.ib(type=RulesByUser, factory=dict)
305311

306312
# The last state group we updated the caches for. If the state_group of
307313
# a new event comes along, we know that we can just return the cached
308314
# result.
309315
# On invalidation of the rules themselves (if the user changes them),
310316
# we invalidate everything and set state_group to `object()`
311-
state_group = attr.ib(type=Union[object, int], factory=object)
317+
state_group = attr.ib(type=StateGroup, factory=object)
312318

313319
# A sequence number to keep track of when we're allowed to update the
314320
# cache. We bump the sequence number when we invalidate the cache. If
@@ -532,7 +538,13 @@ async def _update_rules_with_member_event_ids(
532538

533539
self.update_cache(sequence, members, ret_rules_by_user, state_group)
534540

535-
def update_cache(self, sequence, members, rules_by_user, state_group) -> None:
541+
def update_cache(
542+
self,
543+
sequence: int,
544+
members: MemberMap,
545+
rules_by_user: RulesByUser,
546+
state_group: StateGroup,
547+
) -> None:
536548
if sequence == self.data.sequence:
537549
self.data.member_map.update(members)
538550
self.data.rules_by_user = rules_by_user

synapse/push/clientformat.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
from synapse.types import UserID
2020

2121

22-
def format_push_rules_for_user(user: UserID, ruleslist) -> Dict[str, Dict[str, list]]:
22+
def format_push_rules_for_user(
23+
user: UserID, ruleslist: List
24+
) -> Dict[str, Dict[str, list]]:
2325
"""Converts a list of rawrules and a enabled map into nested dictionaries
2426
to match the Matrix client-server format for push rules"""
2527

synapse/push/httppusher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,10 @@ async def dispatch_push(
403403
rejected = resp["rejected"]
404404
return rejected
405405

406-
async def _send_badge(self, badge):
406+
async def _send_badge(self, badge: int) -> None:
407407
"""
408408
Args:
409-
badge (int): number of unread messages
409+
badge: number of unread messages
410410
"""
411411
logger.debug("Sending updated badge count %d to %s", badge, self.name)
412412
d = {

synapse/storage/databases/main/push_rule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
import abc
1616
import logging
17-
from typing import List, Tuple, Union
17+
from typing import Dict, List, Tuple, Union
1818

1919
from synapse.api.errors import NotFoundError, StoreError
2020
from synapse.push.baserules import list_with_base_rules
@@ -139,7 +139,7 @@ async def get_push_rules_for_user(self, user_id):
139139
return _load_rules(rows, enabled_map, use_new_defaults)
140140

141141
@cached(max_entries=5000)
142-
async def get_push_rules_enabled_for_user(self, user_id):
142+
async def get_push_rules_enabled_for_user(self, user_id) -> Dict[str, bool]:
143143
results = await self.db_pool.simple_select_list(
144144
table="push_rules_enable",
145145
keyvalues={"user_name": user_id},

0 commit comments

Comments
 (0)