This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Convert internal pusher dicts to attrs #8940
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9221de8
Add more type hints to ID generators.
clokep 6010ffe
Add type hints to pusher store.
clokep e224f5e
Use attrs instead of dicts for pusher configs.
clokep c00eba0
Convert throttle params into attrs.
clokep 0b06c1a
Add newsfragment.
clokep 7d34b7d
Merge remote-tracking branch 'origin/develop' into clokep/type-push
clokep 624ee31
Review comments.
clokep a2dfc89
Lint.
clokep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add type hints to push module. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,9 @@ | |
# limitations under the License. | ||
|
||
import logging | ||
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional | ||
from typing import TYPE_CHECKING, Callable, Dict, Optional | ||
|
||
from synapse.push import Pusher | ||
from synapse.push import Pusher, PusherConfig | ||
from synapse.push.emailpusher import EmailPusher | ||
from synapse.push.httppusher import HttpPusher | ||
from synapse.push.mailer import Mailer | ||
|
@@ -34,7 +34,7 @@ def __init__(self, hs: "HomeServer"): | |
|
||
self.pusher_types = { | ||
"http": HttpPusher | ||
} # type: Dict[str, Callable[[HomeServer, dict], Pusher]] | ||
} # type: Dict[str, Callable[[HomeServer, PusherConfig], Pusher]] | ||
|
||
logger.info("email enable notifs: %r", hs.config.email_enable_notifs) | ||
if hs.config.email_enable_notifs: | ||
|
@@ -47,18 +47,18 @@ def __init__(self, hs: "HomeServer"): | |
|
||
logger.info("defined email pusher type") | ||
|
||
def create_pusher(self, pusherdict: Dict[str, Any]) -> Optional[Pusher]: | ||
kind = pusherdict["kind"] | ||
def create_pusher(self, pusher_config: PusherConfig) -> Optional[Pusher]: | ||
kind = pusher_config.kind | ||
f = self.pusher_types.get(kind, None) | ||
if not f: | ||
return None | ||
logger.debug("creating %s pusher for %r", kind, pusherdict) | ||
return f(self.hs, pusherdict) | ||
logger.debug("creating %s pusher for %r", kind, pusher_config) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the attrs class give a sane repr? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. attrs gives decent reprs, something like (the data is made up...):
|
||
return f(self.hs, pusher_config) | ||
|
||
def _create_email_pusher( | ||
self, _hs: "HomeServer", pusherdict: Dict[str, Any] | ||
self, _hs: "HomeServer", pusher_config: PusherConfig | ||
) -> EmailPusher: | ||
app_name = self._app_name_from_pusherdict(pusherdict) | ||
app_name = self._app_name_from_pusherdict(pusher_config) | ||
mailer = self.mailers.get(app_name) | ||
if not mailer: | ||
mailer = Mailer( | ||
|
@@ -68,10 +68,10 @@ def _create_email_pusher( | |
template_text=self._notif_template_text, | ||
) | ||
self.mailers[app_name] = mailer | ||
return EmailPusher(self.hs, pusherdict, mailer) | ||
return EmailPusher(self.hs, pusher_config, mailer) | ||
|
||
def _app_name_from_pusherdict(self, pusherdict: Dict[str, Any]) -> str: | ||
data = pusherdict["data"] | ||
def _app_name_from_pusherdict(self, pusher_config: PusherConfig) -> str: | ||
data = pusher_config.data | ||
|
||
if isinstance(data, dict): | ||
brand = data.get("brand") | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.