disallow-untyped-defs for synapse.push (#11023)
parent
5e29d417fc
commit
e0f11ae4a5
|
@ -0,0 +1 @@
|
||||||
|
Add additional type hints for `synapse.push`.
|
3
mypy.ini
3
mypy.ini
|
@ -96,6 +96,9 @@ files =
|
||||||
[mypy-synapse.handlers.*]
|
[mypy-synapse.handlers.*]
|
||||||
disallow_untyped_defs = True
|
disallow_untyped_defs = True
|
||||||
|
|
||||||
|
[mypy-synapse.push.*]
|
||||||
|
disallow_untyped_defs = True
|
||||||
|
|
||||||
[mypy-synapse.rest.*]
|
[mypy-synapse.rest.*]
|
||||||
disallow_untyped_defs = True
|
disallow_untyped_defs = True
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ class Pusher(metaclass=abc.ABCMeta):
|
||||||
self._start_processing()
|
self._start_processing()
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def _start_processing(self):
|
def _start_processing(self) -> None:
|
||||||
"""Start processing push notifications."""
|
"""Start processing push notifications."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
|
@ -290,6 +290,12 @@ def _condition_checker(
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
MemberMap = Dict[str, Tuple[str, str]]
|
||||||
|
Rule = Dict[str, dict]
|
||||||
|
RulesByUser = Dict[str, List[Rule]]
|
||||||
|
StateGroup = Union[object, int]
|
||||||
|
|
||||||
|
|
||||||
@attr.s(slots=True)
|
@attr.s(slots=True)
|
||||||
class RulesForRoomData:
|
class RulesForRoomData:
|
||||||
"""The data stored in the cache by `RulesForRoom`.
|
"""The data stored in the cache by `RulesForRoom`.
|
||||||
|
@ -299,16 +305,16 @@ class RulesForRoomData:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# event_id -> (user_id, state)
|
# event_id -> (user_id, state)
|
||||||
member_map = attr.ib(type=Dict[str, Tuple[str, str]], factory=dict)
|
member_map = attr.ib(type=MemberMap, factory=dict)
|
||||||
# user_id -> rules
|
# user_id -> rules
|
||||||
rules_by_user = attr.ib(type=Dict[str, List[Dict[str, dict]]], factory=dict)
|
rules_by_user = attr.ib(type=RulesByUser, factory=dict)
|
||||||
|
|
||||||
# The last state group we updated the caches for. If the state_group of
|
# The last state group we updated the caches for. If the state_group of
|
||||||
# a new event comes along, we know that we can just return the cached
|
# a new event comes along, we know that we can just return the cached
|
||||||
# result.
|
# result.
|
||||||
# On invalidation of the rules themselves (if the user changes them),
|
# On invalidation of the rules themselves (if the user changes them),
|
||||||
# we invalidate everything and set state_group to `object()`
|
# we invalidate everything and set state_group to `object()`
|
||||||
state_group = attr.ib(type=Union[object, int], factory=object)
|
state_group = attr.ib(type=StateGroup, factory=object)
|
||||||
|
|
||||||
# A sequence number to keep track of when we're allowed to update the
|
# A sequence number to keep track of when we're allowed to update the
|
||||||
# cache. We bump the sequence number when we invalidate the cache. If
|
# cache. We bump the sequence number when we invalidate the cache. If
|
||||||
|
@ -532,7 +538,13 @@ class RulesForRoom:
|
||||||
|
|
||||||
self.update_cache(sequence, members, ret_rules_by_user, state_group)
|
self.update_cache(sequence, members, ret_rules_by_user, state_group)
|
||||||
|
|
||||||
def update_cache(self, sequence, members, rules_by_user, state_group) -> None:
|
def update_cache(
|
||||||
|
self,
|
||||||
|
sequence: int,
|
||||||
|
members: MemberMap,
|
||||||
|
rules_by_user: RulesByUser,
|
||||||
|
state_group: StateGroup,
|
||||||
|
) -> None:
|
||||||
if sequence == self.data.sequence:
|
if sequence == self.data.sequence:
|
||||||
self.data.member_map.update(members)
|
self.data.member_map.update(members)
|
||||||
self.data.rules_by_user = rules_by_user
|
self.data.rules_by_user = rules_by_user
|
||||||
|
|
|
@ -19,7 +19,9 @@ from synapse.push.rulekinds import PRIORITY_CLASS_INVERSE_MAP, PRIORITY_CLASS_MA
|
||||||
from synapse.types import UserID
|
from synapse.types import UserID
|
||||||
|
|
||||||
|
|
||||||
def format_push_rules_for_user(user: UserID, ruleslist) -> Dict[str, Dict[str, list]]:
|
def format_push_rules_for_user(
|
||||||
|
user: UserID, ruleslist: List
|
||||||
|
) -> Dict[str, Dict[str, list]]:
|
||||||
"""Converts a list of rawrules and a enabled map into nested dictionaries
|
"""Converts a list of rawrules and a enabled map into nested dictionaries
|
||||||
to match the Matrix client-server format for push rules"""
|
to match the Matrix client-server format for push rules"""
|
||||||
|
|
||||||
|
|
|
@ -403,10 +403,10 @@ class HttpPusher(Pusher):
|
||||||
rejected = resp["rejected"]
|
rejected = resp["rejected"]
|
||||||
return rejected
|
return rejected
|
||||||
|
|
||||||
async def _send_badge(self, badge):
|
async def _send_badge(self, badge: int) -> None:
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
badge (int): number of unread messages
|
badge: number of unread messages
|
||||||
"""
|
"""
|
||||||
logger.debug("Sending updated badge count %d to %s", badge, self.name)
|
logger.debug("Sending updated badge count %d to %s", badge, self.name)
|
||||||
d = {
|
d = {
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import abc
|
import abc
|
||||||
import logging
|
import logging
|
||||||
from typing import List, Tuple, Union
|
from typing import Dict, List, Tuple, Union
|
||||||
|
|
||||||
from synapse.api.errors import NotFoundError, StoreError
|
from synapse.api.errors import NotFoundError, StoreError
|
||||||
from synapse.push.baserules import list_with_base_rules
|
from synapse.push.baserules import list_with_base_rules
|
||||||
|
@ -139,7 +139,7 @@ class PushRulesWorkerStore(
|
||||||
return _load_rules(rows, enabled_map, use_new_defaults)
|
return _load_rules(rows, enabled_map, use_new_defaults)
|
||||||
|
|
||||||
@cached(max_entries=5000)
|
@cached(max_entries=5000)
|
||||||
async def get_push_rules_enabled_for_user(self, user_id):
|
async def get_push_rules_enabled_for_user(self, user_id) -> Dict[str, bool]:
|
||||||
results = await self.db_pool.simple_select_list(
|
results = await self.db_pool.simple_select_list(
|
||||||
table="push_rules_enable",
|
table="push_rules_enable",
|
||||||
keyvalues={"user_name": user_id},
|
keyvalues={"user_name": user_id},
|
||||||
|
|
Loading…
Reference in New Issue