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

Commit

Permalink
Remove unnecessary parentheses around return statements (#5931)
Browse files Browse the repository at this point in the history
Python will return a tuple whether there are parentheses around the returned values or not.

I'm just sick of my editor complaining about this all over the place :)
  • Loading branch information
anoadragon453 authored Aug 30, 2019
1 parent 4fca313 commit 4548d1f
Show file tree
Hide file tree
Showing 81 changed files with 287 additions and 286 deletions.
1 change: 1 addition & 0 deletions changelog.d/5931.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove unnecessary parentheses in return statements.
14 changes: 7 additions & 7 deletions synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,25 +276,25 @@ def _get_appservice_user_id(self, request):
self.get_access_token_from_request(request)
)
if app_service is None:
return (None, None)
return None, None

if app_service.ip_range_whitelist:
ip_address = IPAddress(self.hs.get_ip_from_request(request))
if ip_address not in app_service.ip_range_whitelist:
return (None, None)
return None, None

if b"user_id" not in request.args:
return (app_service.sender, app_service)
return app_service.sender, app_service

user_id = request.args[b"user_id"][0].decode("utf8")
if app_service.sender == user_id:
return (app_service.sender, app_service)
return app_service.sender, app_service

if not app_service.is_interested_in_user(user_id):
raise AuthError(403, "Application service cannot masquerade as this user.")
if not (yield self.store.get_user_by_id(user_id)):
raise AuthError(403, "Application service has not registered this user")
return (user_id, app_service)
return user_id, app_service

@defer.inlineCallbacks
def get_user_by_access_token(self, token, rights="access"):
Expand Down Expand Up @@ -694,7 +694,7 @@ def check_in_room_or_world_readable(self, room_id, user_id):
# * The user is a guest user, and has joined the room
# else it will throw.
member_event = yield self.check_user_was_in_room(room_id, user_id)
return (member_event.membership, member_event.event_id)
return member_event.membership, member_event.event_id
except AuthError:
visibility = yield self.state.get_current_state(
room_id, EventTypes.RoomHistoryVisibility, ""
Expand All @@ -703,7 +703,7 @@ def check_in_room_or_world_readable(self, room_id, user_id):
visibility
and visibility.content["history_visibility"] == "world_readable"
):
return (Membership.JOIN, None)
return Membership.JOIN, None
return
raise AuthError(
403, "Guest access not allowed", errcode=Codes.GUEST_ACCESS_FORBIDDEN
Expand Down
8 changes: 4 additions & 4 deletions synapse/app/frontend_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def on_GET(self, request, user_id):
except HttpResponseException as e:
raise e.to_synapse_error()

return (200, result)
return 200, result

@defer.inlineCallbacks
def on_PUT(self, request, user_id):
yield self.auth.get_user_by_req(request)
return (200, {})
return 200, {}


class KeyUploadServlet(RestServlet):
Expand Down Expand Up @@ -126,11 +126,11 @@ def on_POST(self, request, device_id):
self.main_uri + request.uri.decode("ascii"), body, headers=headers
)

return (200, result)
return 200, result
else:
# Just interested in counts.
result = yield self.store.count_e2e_one_time_keys(user_id, device_id)
return (200, {"one_time_key_counts": result})
return 200, {"one_time_key_counts": result}


class FrontendProxySlavedStore(
Expand Down
4 changes: 2 additions & 2 deletions synapse/crypto/event_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def compute_content_hash(event_dict, hash_algorithm):
event_json_bytes = encode_canonical_json(event_dict)

hashed = hash_algorithm(event_json_bytes)
return (hashed.name, hashed.digest())
return hashed.name, hashed.digest()


def compute_event_reference_hash(event, hash_algorithm=hashlib.sha256):
Expand All @@ -106,7 +106,7 @@ def compute_event_reference_hash(event, hash_algorithm=hashlib.sha256):
event_dict.pop("unsigned", None)
event_json_bytes = encode_canonical_json(event_dict)
hashed = hash_algorithm(event_json_bytes)
return (hashed.name, hashed.digest())
return hashed.name, hashed.digest()


def compute_event_signature(event_dict, signature_name, signing_key):
Expand Down
8 changes: 4 additions & 4 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def get_state_for_room(self, destination, room_id, event_id):

auth_chain.sort(key=lambda e: e.depth)

return (pdus, auth_chain)
return pdus, auth_chain
except HttpResponseException as e:
if e.code == 400 or e.code == 404:
logger.info("Failed to use get_room_state_ids API, falling back")
Expand Down Expand Up @@ -404,7 +404,7 @@ def get_state_for_room(self, destination, room_id, event_id):

signed_auth.sort(key=lambda e: e.depth)

return (signed_pdus, signed_auth)
return signed_pdus, signed_auth

@defer.inlineCallbacks
def get_events_from_store_or_dest(self, destination, room_id, event_ids):
Expand All @@ -429,7 +429,7 @@ def get_events_from_store_or_dest(self, destination, room_id, event_ids):
missing_events.discard(k)

if not missing_events:
return (signed_events, failed_to_fetch)
return signed_events, failed_to_fetch

logger.debug(
"Fetching unknown state/auth events %s for room %s",
Expand Down Expand Up @@ -465,7 +465,7 @@ def get_events_from_store_or_dest(self, destination, room_id, event_ids):
# We removed all events we successfully fetched from `batch`
failed_to_fetch.update(batch)

return (signed_events, failed_to_fetch)
return signed_events, failed_to_fetch

@defer.inlineCallbacks
@log_function
Expand Down
22 changes: 11 additions & 11 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def on_backfill_request(self, origin, room_id, versions, limit):

res = self._transaction_from_pdus(pdus).get_dict()

return (200, res)
return 200, res

@defer.inlineCallbacks
@log_function
Expand Down Expand Up @@ -163,7 +163,7 @@ def _handle_incoming_transaction(self, origin, transaction, request_time):
yield self.transaction_actions.set_response(
origin, transaction, 400, response
)
return (400, response)
return 400, response

received_pdus_counter.inc(len(transaction.pdus))

Expand Down Expand Up @@ -265,7 +265,7 @@ def process_pdus_for_room(room_id):
logger.debug("Returning: %s", str(response))

yield self.transaction_actions.set_response(origin, transaction, 200, response)
return (200, response)
return 200, response

@defer.inlineCallbacks
def received_edu(self, origin, edu_type, content):
Expand Down Expand Up @@ -298,7 +298,7 @@ def on_context_state_request(self, origin, room_id, event_id):
event_id,
)

return (200, resp)
return 200, resp

@defer.inlineCallbacks
def on_state_ids_request(self, origin, room_id, event_id):
Expand All @@ -315,7 +315,7 @@ def on_state_ids_request(self, origin, room_id, event_id):
state_ids = yield self.handler.get_state_ids_for_pdu(room_id, event_id)
auth_chain_ids = yield self.store.get_auth_chain_ids(state_ids)

return (200, {"pdu_ids": state_ids, "auth_chain_ids": auth_chain_ids})
return 200, {"pdu_ids": state_ids, "auth_chain_ids": auth_chain_ids}

@defer.inlineCallbacks
def _on_context_state_request_compute(self, room_id, event_id):
Expand Down Expand Up @@ -345,15 +345,15 @@ def on_pdu_request(self, origin, event_id):
pdu = yield self.handler.get_persisted_pdu(origin, event_id)

if pdu:
return (200, self._transaction_from_pdus([pdu]).get_dict())
return 200, self._transaction_from_pdus([pdu]).get_dict()
else:
return (404, "")
return 404, ""

@defer.inlineCallbacks
def on_query_request(self, query_type, args):
received_queries_counter.labels(query_type).inc()
resp = yield self.registry.on_query(query_type, args)
return (200, resp)
return 200, resp

@defer.inlineCallbacks
def on_make_join_request(self, origin, room_id, user_id, supported_versions):
Expand Down Expand Up @@ -435,7 +435,7 @@ def on_send_leave_request(self, origin, content, room_id):

logger.debug("on_send_leave_request: pdu sigs: %s", pdu.signatures)
yield self.handler.on_send_leave_request(origin, pdu)
return (200, {})
return 200, {}

@defer.inlineCallbacks
def on_event_auth(self, origin, room_id, event_id):
Expand All @@ -446,7 +446,7 @@ def on_event_auth(self, origin, room_id, event_id):
time_now = self._clock.time_msec()
auth_pdus = yield self.handler.on_event_auth(event_id)
res = {"auth_chain": [a.get_pdu_json(time_now) for a in auth_pdus]}
return (200, res)
return 200, res

@defer.inlineCallbacks
def on_query_auth_request(self, origin, content, room_id, event_id):
Expand Down Expand Up @@ -499,7 +499,7 @@ def on_query_auth_request(self, origin, content, room_id, event_id):
"missing": ret.get("missing", []),
}

return (200, send_content)
return 200, send_content

@log_function
def on_query_client_keys(self, origin, content):
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def get_new_events(self, user, from_key, **kwargs):
{"type": account_data_type, "content": content, "room_id": room_id}
)

return (results, current_stream_id)
return results, current_stream_id

@defer.inlineCallbacks
def get_pagination_rows(self, user, config, key):
return ([], config.to_id)
return [], config.to_id
8 changes: 4 additions & 4 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def check_auth(self, flows, clientdict, clientip, password_servlet=False):
creds,
list(clientdict),
)
return (creds, clientdict, session["id"])
return creds, clientdict, session["id"]

ret = self._auth_dict_for_flows(flows, session)
ret["completed"] = list(creds)
Expand Down Expand Up @@ -722,7 +722,7 @@ def validate_login(self, username, login_submission):
known_login_type = True
is_valid = yield provider.check_password(qualified_user_id, password)
if is_valid:
return (qualified_user_id, None)
return qualified_user_id, None

if not hasattr(provider, "get_supported_login_types") or not hasattr(
provider, "check_auth"
Expand Down Expand Up @@ -766,7 +766,7 @@ def validate_login(self, username, login_submission):
)

if canonical_user_id:
return (canonical_user_id, None)
return canonical_user_id, None

if not known_login_type:
raise SynapseError(400, "Unknown login type %s" % login_type)
Expand Down Expand Up @@ -816,7 +816,7 @@ def check_password_provider_3pid(self, medium, address, password):
result = (result, None)
return result

return (None, None)
return None, None

@defer.inlineCallbacks
def _check_local_password(self, user_id, password):
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ def _make_and_verify_event(
assert event.user_id == user_id
assert event.state_key == user_id
assert event.room_id == room_id
return (origin, event, format_ver)
return origin, event, format_ver

@defer.inlineCallbacks
@log_function
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def _check_in_room_or_world_readable(self, room_id, user_id):
# * The user is a guest user, and has joined the room
# else it will throw.
member_event = yield self.auth.check_user_was_in_room(room_id, user_id)
return (member_event.membership, member_event.event_id)
return member_event.membership, member_event.event_id
return
except AuthError:
visibility = yield self.state_handler.get_current_state(
Expand All @@ -459,7 +459,7 @@ def _check_in_room_or_world_readable(self, room_id, user_id):
visibility
and visibility.content["history_visibility"] == "world_readable"
):
return (Membership.JOIN, None)
return Membership.JOIN, None
return
raise AuthError(
403, "Guest access not allowed", errcode=Codes.GUEST_ACCESS_FORBIDDEN
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ def get_new_events(
#
# Hence this guard where we just return nothing so that the sync
# doesn't return. C.f. #5503.
return ([], max_token)
return [], max_token

presence = self.get_presence_handler()
stream_change_cache = self.store.presence_stream_cache
Expand Down Expand Up @@ -1279,7 +1279,7 @@ def get_interested_parties(store, states):
# Always notify self
users_to_states.setdefault(state.user_id, []).append(state)

return (room_ids_to_states, users_to_states)
return room_ids_to_states, users_to_states


@defer.inlineCallbacks
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def get_new_events(self, from_key, room_ids, **kwargs):
to_key = yield self.get_current_key()

if from_key == to_key:
return ([], to_key)
return [], to_key

events = yield self.store.get_linearized_receipts_for_rooms(
room_ids, from_key=from_key, to_key=to_key
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def register_device(self, user_id, device_id, initial_display_name, is_guest=Fal
initial_display_name=initial_display_name,
is_guest=is_guest,
)
return (r["device_id"], r["access_token"])
return r["device_id"], r["access_token"]

valid_until_ms = None
if self.session_lifetime is not None:
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ def _ask_id_server_for_third_party_invite(
if not public_keys:
public_keys.append(fallback_public_key)
display_name = data["display_name"]
return (token, public_keys, fallback_public_key, display_name)
return token, public_keys, fallback_public_key, display_name

@defer.inlineCallbacks
def _is_host_in_room(self, current_state_ids):
Expand Down
8 changes: 4 additions & 4 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def ephemeral_by_room(self, sync_result_builder, now_token, since_token=None):
event_copy = {k: v for (k, v) in iteritems(event) if k != "room_id"}
ephemeral_by_room.setdefault(room_id, []).append(event_copy)

return (now_token, ephemeral_by_room)
return now_token, ephemeral_by_room

@defer.inlineCallbacks
def _load_filtered_recents(
Expand Down Expand Up @@ -1332,7 +1332,7 @@ def _generate_sync_entry_for_rooms(self, sync_result_builder, account_data_by_ro
)
if not tags_by_room:
logger.debug("no-oping sync")
return ([], [], [], [])
return [], [], [], []

ignored_account_data = yield self.store.get_global_account_data_by_type_for_user(
"m.ignored_user_list", user_id=user_id
Expand Down Expand Up @@ -1642,7 +1642,7 @@ def _get_rooms_changed(self, sync_result_builder, ignored_users):
)
room_entries.append(entry)

return (room_entries, invited, newly_joined_rooms, newly_left_rooms)
return room_entries, invited, newly_joined_rooms, newly_left_rooms

@defer.inlineCallbacks
def _get_all_rooms(self, sync_result_builder, ignored_users):
Expand Down Expand Up @@ -1716,7 +1716,7 @@ def _get_all_rooms(self, sync_result_builder, ignored_users):
)
)

return (room_entries, invited, [])
return room_entries, invited, []

@defer.inlineCallbacks
def _generate_room_entry(
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,4 @@ def get_current_key(self):
return self.get_typing_handler()._latest_room_serial

def get_pagination_rows(self, user, pagination_config, key):
return ([], pagination_config.from_key)
return [], pagination_config.from_key
2 changes: 1 addition & 1 deletion synapse/http/federation/well_known_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _fetch_well_known(self, server_name):
cache_period + WELL_KNOWN_REMEMBER_DOMAIN_HAD_VALID,
)

return (result, cache_period)
return result, cache_period

@defer.inlineCallbacks
def _make_well_known_request(self, server_name, retry):
Expand Down
Loading

0 comments on commit 4548d1f

Please sign in to comment.