From e42baf9e1307f2bcddb7cb94c48f9ae1dee4c2fa Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Tue, 19 Jan 2021 14:52:45 +0000 Subject: [PATCH] minor: Clean up args for apply_events. I eliminate the defaults, since the existing code was already specificying values for most things. I move all the booleans to the bottom for both parameters and arguments. I require explicit keywords for everything but user_profile (which is now first). And, finally, I format the code in a more diff-friendly manner. --- zerver/lib/events.py | 26 +++++++++++++++++++------- zerver/tests/test_events.py | 13 +++++++++---- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/zerver/lib/events.py b/zerver/lib/events.py index acb11480a2..d894b66ba0 100644 --- a/zerver/lib/events.py +++ b/zerver/lib/events.py @@ -417,10 +417,16 @@ def fetch_initial_state_data( return state -def apply_events(state: Dict[str, Any], events: Iterable[Dict[str, Any]], - user_profile: UserProfile, client_gravatar: bool, - slim_presence: bool, include_subscribers: bool = True, - fetch_event_types: Optional[Iterable[str]] = None) -> None: +def apply_events( + user_profile: UserProfile, + *, + state: Dict[str, Any], + events: Iterable[Dict[str, Any]], + fetch_event_types: Optional[Iterable[str]], + client_gravatar: bool, + slim_presence: bool, + include_subscribers: bool, +) -> None: for event in events: if fetch_event_types is not None and event['type'] not in fetch_event_types: # TODO: continuing here is not, most precisely, correct. @@ -987,9 +993,15 @@ def do_events_register( # Apply events that came in while we were fetching initial data events = get_user_events(user_profile, queue_id, -1) - apply_events(ret, events, user_profile, include_subscribers=include_subscribers, - client_gravatar=client_gravatar, slim_presence=slim_presence, - fetch_event_types=fetch_event_types) + apply_events( + user_profile, + state=ret, + events=events, + fetch_event_types=fetch_event_types, + client_gravatar=client_gravatar, + slim_presence=slim_presence, + include_subscribers=include_subscribers, + ) post_process_state(user_profile, ret, notification_settings_null) diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 20bc0f3af9..878e7aa697 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -261,10 +261,15 @@ class BaseAction(ZulipTestCase): initial_state = copy.deepcopy(hybrid_state) post_process_state(self.user_profile, initial_state, notification_settings_null) before = orjson.dumps(initial_state) - apply_events(hybrid_state, events, self.user_profile, - client_gravatar=client_gravatar, - slim_presence=slim_presence, - include_subscribers=include_subscribers) + apply_events( + self.user_profile, + state=hybrid_state, + events=events, + fetch_event_types=None, + client_gravatar=client_gravatar, + slim_presence=slim_presence, + include_subscribers=include_subscribers, + ) post_process_state(self.user_profile, hybrid_state, notification_settings_null) after = orjson.dumps(hybrid_state)