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.
This commit is contained in:
Steve Howell
2021-01-19 14:52:45 +00:00
committed by Tim Abbott
parent f2586d2f9b
commit e42baf9e13
2 changed files with 28 additions and 11 deletions

View File

@@ -417,10 +417,16 @@ def fetch_initial_state_data(
return state return state
def apply_events(state: Dict[str, Any], events: Iterable[Dict[str, Any]], def apply_events(
user_profile: UserProfile, client_gravatar: bool, user_profile: UserProfile,
slim_presence: bool, include_subscribers: bool = True, *,
fetch_event_types: Optional[Iterable[str]] = None) -> None: 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: for event in events:
if fetch_event_types is not None and event['type'] not in fetch_event_types: if fetch_event_types is not None and event['type'] not in fetch_event_types:
# TODO: continuing here is not, most precisely, correct. # 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 # Apply events that came in while we were fetching initial data
events = get_user_events(user_profile, queue_id, -1) events = get_user_events(user_profile, queue_id, -1)
apply_events(ret, events, user_profile, include_subscribers=include_subscribers, apply_events(
client_gravatar=client_gravatar, slim_presence=slim_presence, user_profile,
fetch_event_types=fetch_event_types) 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) post_process_state(user_profile, ret, notification_settings_null)

View File

@@ -261,10 +261,15 @@ class BaseAction(ZulipTestCase):
initial_state = copy.deepcopy(hybrid_state) initial_state = copy.deepcopy(hybrid_state)
post_process_state(self.user_profile, initial_state, notification_settings_null) post_process_state(self.user_profile, initial_state, notification_settings_null)
before = orjson.dumps(initial_state) before = orjson.dumps(initial_state)
apply_events(hybrid_state, events, self.user_profile, apply_events(
client_gravatar=client_gravatar, self.user_profile,
slim_presence=slim_presence, state=hybrid_state,
include_subscribers=include_subscribers) 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) post_process_state(self.user_profile, hybrid_state, notification_settings_null)
after = orjson.dumps(hybrid_state) after = orjson.dumps(hybrid_state)