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 tuples returned from methods (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 authored Sep 23, 2021
1 parent 26f2bfe commit aa2c027
Show file tree
Hide file tree
Showing 22 changed files with 33 additions and 32 deletions.
1 change: 1 addition & 0 deletions changelog.d/10889.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean up some unnecessary parentheses in places around the codebase.
2 changes: 1 addition & 1 deletion synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ def read_gc_thresholds(thresholds):
return None
try:
assert len(thresholds) == 3
return (int(thresholds[0]), int(thresholds[1]), int(thresholds[2]))
return int(thresholds[0]), int(thresholds[1]), int(thresholds[2])
except Exception:
raise ConfigError(
"Value of `gc_threshold` must be a list of three integers if set"
Expand Down
4 changes: 2 additions & 2 deletions synapse/federation/sender/per_destination_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ async def _get_device_update_edus(self, limit: int) -> Tuple[List[Edu], int]:

assert len(edus) <= limit, "get_device_updates_by_remote returned too many EDUs"

return (edus, now_stream_id)
return edus, now_stream_id

async def _get_to_device_message_edus(self, limit: int) -> Tuple[List[Edu], int]:
last_device_stream_id = self._last_device_stream_id
Expand Down Expand Up @@ -593,7 +593,7 @@ async def _get_to_device_message_edus(self, limit: int) -> Tuple[List[Edu], int]
stream_id,
)

return (edus, stream_id)
return edus, stream_id

def _start_catching_up(self) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ async def add_display_name_to_third_party_invite(
builder=builder
)
EventValidator().validate_new(event, self.config)
return (event, context)
return event, context

async def _check_signature(self, event: EventBase, context: EventContext) -> None:
"""
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ async def create_event(

self.validator.validate_new(event, self.config)

return (event, context)
return event, context

async def _is_exempt_from_privacy_policy(
self, builder: EventBuilder, requester: Requester
Expand Down Expand Up @@ -1004,7 +1004,7 @@ async def create_new_client_event(

logger.debug("Created event %s", event.event_id)

return (event, context)
return event, context

@measure_func("handle_new_client_event")
async def handle_new_client_event(
Expand Down
4 changes: 2 additions & 2 deletions synapse/handlers/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ async def get_new_events(
if self.config.experimental.msc2285_enabled:
events = ReceiptEventSource.filter_out_hidden(events, user.to_string())

return (events, to_key)
return events, to_key

async def get_new_events_as(
self, from_key: int, service: ApplicationService
Expand Down Expand Up @@ -270,7 +270,7 @@ async def get_new_events_as(

events.append(event)

return (events, to_key)
return events, to_key

def get_current_key(self, direction: str = "f") -> int:
return self.store.get_max_receipt_stream_id()
2 changes: 1 addition & 1 deletion synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ async def get_new_events(
else:
end_key = to_key

return (events, end_key)
return events, end_key

def get_current_key(self) -> RoomStreamToken:
return self.store.get_room_max_token()
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/room_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,4 +1179,4 @@ def _child_events_comparison_key(
order = None

# Items without an order come last.
return (order is None, order, child.origin_server_ts, child.room_id)
return order is None, order, child.origin_server_ts, child.room_id
4 changes: 2 additions & 2 deletions synapse/handlers/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ async def get_new_events_as(

events.append(self._make_event_for(room_id))

return (events, handler._latest_room_serial)
return events, handler._latest_room_serial

async def get_new_events(
self,
Expand All @@ -507,7 +507,7 @@ async def get_new_events(

events.append(self._make_event_for(room_id))

return (events, handler._latest_room_serial)
return events, handler._latest_room_serial

def get_current_key(self) -> int:
return self.get_typing_handler()._latest_room_serial
2 changes: 1 addition & 1 deletion synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ async def get_file(
request.method,
request.uri.decode("ascii"),
)
return (length, headers)
return length, headers


def _flatten_response_never_received(e):
Expand Down
4 changes: 2 additions & 2 deletions synapse/rest/admin/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async def on_GET(
members = await self.store.get_users_in_room(room_id)
ret["joined_local_devices"] = await self.store.count_devices_by_users(members)

return (200, ret)
return 200, ret

async def on_DELETE(
self, request: SynapseRequest, room_id: str
Expand Down Expand Up @@ -668,4 +668,4 @@ async def _delete_room(
if purge:
await pagination_handler.purge_room(room_id, force=force_purge)

return (200, ret)
return 200, ret
4 changes: 2 additions & 2 deletions synapse/rest/client/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
if dehydrated_device is not None:
(device_id, device_data) = dehydrated_device
result = {"device_id": device_id, "device_data": device_data}
return (200, result)
return 200, result
else:
raise errors.NotFoundError("No dehydrated device available")

Expand Down Expand Up @@ -293,7 +293,7 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
submission["device_id"],
)

return (200, result)
return 200, result


def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
Expand Down
4 changes: 2 additions & 2 deletions synapse/rest/client/password_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, hs: "HomeServer"):

def on_GET(self, request: Request) -> Tuple[int, JsonDict]:
if not self.enabled or not self.policy:
return (200, {})
return 200, {}

policy = {}

Expand All @@ -54,7 +54,7 @@ def on_GET(self, request: Request) -> Tuple[int, JsonDict]:
if param in self.policy:
policy["m.%s" % param] = self.policy[param]

return (200, policy)
return 200, policy


def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/databases/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def get_updated_account_data_for_user_txn(txn):
user_id, int(stream_id)
)
if not changed:
return ({}, {})
return {}, {}

return await self.db_pool.runInteraction(
"get_updated_account_data_for_user", get_updated_account_data_for_user_txn
Expand Down
6 changes: 3 additions & 3 deletions synapse/storage/databases/main/deviceinbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def get_new_messages_for_device(
user_id, last_stream_id
)
if not has_changed:
return ([], current_stream_id)
return [], current_stream_id

def get_new_messages_for_device_txn(txn):
sql = (
Expand Down Expand Up @@ -240,11 +240,11 @@ async def get_new_device_msgs_for_remote(
)
if not has_changed or last_stream_id == current_stream_id:
log_kv({"message": "No new messages in stream"})
return ([], current_stream_id)
return [], current_stream_id

if limit <= 0:
# This can happen if we run out of room for EDUs in the transaction.
return ([], last_stream_id)
return [], last_stream_id

@trace
def get_new_messages_for_remote_destination_txn(txn):
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/databases/main/events_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ async def get_event_ordering(self, event_id):
if not res:
raise SynapseError(404, "Could not find event %s" % (event_id,))

return (int(res["topological_ordering"]), int(res["stream_ordering"]))
return int(res["topological_ordering"]), int(res["stream_ordering"])

async def get_next_event_to_expire(self) -> Optional[Tuple[str, int]]:
"""Retrieve the entry with the lowest expiry timestamp in the event_expiry
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/databases/main/state_deltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def get_current_state_deltas(
# if the CSDs haven't changed between prev_stream_id and now, we
# know for certain that they haven't changed between prev_stream_id and
# max_stream_id.
return (max_stream_id, [])
return max_stream_id, []

def get_current_state_deltas_txn(txn):
# First we calculate the max stream id that will give us less than
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ async def get_recent_events_for_room(

self._set_before_and_after(events, rows)

return (events, token)
return events, token

async def get_recent_event_ids_for_room(
self, room_id: str, limit: int, end_token: RoomStreamToken
Expand Down Expand Up @@ -1242,7 +1242,7 @@ async def paginate_room_events(

self._set_before_and_after(events, rows)

return (events, token)
return events, token

@cached()
async def get_id_for_instance(self, instance_name: str) -> int:
Expand Down
2 changes: 1 addition & 1 deletion synapse/streams/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def from_request(
raise SynapseError(400, "Invalid request.")

def __repr__(self) -> str:
return ("PaginationConfig(from_tok=%r, to_tok=%r, direction=%r, limit=%r)") % (
return "PaginationConfig(from_tok=%r, to_tok=%r, direction=%r, limit=%r)" % (
self.from_token,
self.to_token,
self.direction,
Expand Down
4 changes: 2 additions & 2 deletions synapse/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def as_historical_tuple(self) -> Tuple[int, int]:
"Cannot call `RoomStreamToken.as_historical_tuple` on live token"
)

return (self.topological, self.stream)
return self.topological, self.stream

def get_stream_pos_for_instance(self, instance_name: str) -> int:
"""Get the stream position that the given writer was at at this token.
Expand Down Expand Up @@ -766,7 +766,7 @@ def get_verify_key_from_cross_signing_key(key_info):
raise ValueError("Invalid key")
# and return that one key
for key_id, key_data in keys.items():
return (key_id, decode_verify_key_bytes(key_id, decode_base64(key_data)))
return key_id, decode_verify_key_bytes(key_id, decode_base64(key_data))


@attr.s(auto_attribs=True, frozen=True, slots=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async def get_events(self, event_ids, **kwargs):
}

async def get_state_group_delta(self, name):
return (None, None)
return None, None

def register_events(self, events):
for e in events:
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def trigger(
)
return code, response
except CodeMessageException as e:
return (e.code, cs_error(e.msg, code=e.errcode))
return e.code, cs_error(e.msg, code=e.errcode)

raise KeyError("No event can handle %s" % path)

Expand Down

0 comments on commit aa2c027

Please sign in to comment.