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

Commit f8c7b31

Browse files
committed
Add some more docstrings
1 parent bb97501 commit f8c7b31

File tree

1 file changed

+54
-2
lines changed

1 file changed

+54
-2
lines changed

synapse/federation/federation_client.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,32 @@ async def get_space_summary(
10731073
max_rooms_per_space: Optional[int],
10741074
exclude_rooms: List[str],
10751075
) -> "FederationSpaceSummaryResult":
1076+
"""
1077+
Call other servers to get a summary of the given space
1078+
1079+
1080+
Args:
1081+
destinations: The remote servers. We will try them in turn, omitting any
1082+
that have been blacklisted.
1083+
1084+
room_id: ID of the space to be queried
1085+
1086+
suggested_only: If true, ask the remote server to only return children
1087+
with the "suggested" flag set
1088+
1089+
max_rooms_per_space: A limit on the number of children to return for each
1090+
space
1091+
1092+
exclude_rooms: A list of room IDs to tell the remote server to skip
1093+
1094+
Returns:
1095+
a parsed FederationSpaceSummaryResult
1096+
1097+
Raises:
1098+
SynapseError if we were unable to get a valid summary from any of the
1099+
remote servers
1100+
"""
1101+
10761102
async def send_request(destination: str) -> FederationSpaceSummaryResult:
10771103
res = await self.transport_layer.get_space_summary(
10781104
destination=destination,
@@ -1097,6 +1123,13 @@ async def send_request(destination: str) -> FederationSpaceSummaryResult:
10971123

10981124
@attr.s(frozen=True, slots=True)
10991125
class FederationSpaceSummaryEventResult:
1126+
"""Represents a single event in the result of a successful get_space_summary call.
1127+
1128+
It's essentially just a serialised event object, but we do a bit of parsing and
1129+
validation in `from_json_dict` and store some of the validated properties in
1130+
object attributes.
1131+
"""
1132+
11001133
event_type = attr.ib(type=str)
11011134
state_key = attr.ib(type=str)
11021135
via = attr.ib(type=Sequence[str])
@@ -1105,7 +1138,16 @@ class FederationSpaceSummaryEventResult:
11051138
data = attr.ib(type=JsonDict)
11061139

11071140
@classmethod
1108-
def from_json_dict(cls, d: JsonDict):
1141+
def from_json_dict(cls, d: JsonDict) -> "FederationSpaceSummaryEventResult":
1142+
"""Parse an event within the result of a /spaces/ request
1143+
1144+
Args:
1145+
d: json object to be parsed
1146+
1147+
Raises:
1148+
ValueError if d is not a valid event
1149+
"""
1150+
11091151
event_type = d.get("type")
11101152
if not isinstance(event_type, str):
11111153
raise ValueError("Invalid event: 'event_type' must be a str")
@@ -1129,11 +1171,21 @@ def from_json_dict(cls, d: JsonDict):
11291171

11301172
@attr.s(frozen=True, slots=True)
11311173
class FederationSpaceSummaryResult:
1174+
"""Represents the data returned by a successful get_space_summary call."""
1175+
11321176
rooms = attr.ib(type=Sequence[JsonDict])
11331177
events = attr.ib(type=Sequence[FederationSpaceSummaryEventResult])
11341178

11351179
@classmethod
1136-
def from_json_dict(cls, d: JsonDict):
1180+
def from_json_dict(cls, d: JsonDict) -> "FederationSpaceSummaryResult":
1181+
"""Parse the result of a /spaces/ request
1182+
1183+
Args:
1184+
d: json object to be parsed
1185+
1186+
Raises:
1187+
ValueError if d is not a valid /spaces/ response
1188+
"""
11371189
rooms = d.get("rooms")
11381190
if not isinstance(rooms, Sequence):
11391191
raise ValueError("'rooms' must be a list")

0 commit comments

Comments
 (0)