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

Add type hints to the federation handler and server. #9743

Merged
merged 4 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/9743.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing type hints to federation handler and server.
26 changes: 13 additions & 13 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,22 +739,20 @@ async def _handle_received_pdu(self, origin: str, pdu: EventBase) -> None:

await self.handler.on_receive_pdu(origin, pdu, sent_to_us_directly=True)

def __str__(self):
def __str__(self) -> str:
return "<ReplicationLayer(%s)>" % self.server_name

async def exchange_third_party_invite(
self, sender_user_id: str, target_user_id: str, room_id: str, signed: Dict
):
ret = await self.handler.exchange_third_party_invite(
) -> None:
await self.handler.exchange_third_party_invite(
sender_user_id, target_user_id, room_id, signed
)
return ret

async def on_exchange_third_party_invite_request(self, event_dict: Dict):
ret = await self.handler.on_exchange_third_party_invite_request(event_dict)
return ret
async def on_exchange_third_party_invite_request(self, event_dict: Dict) -> None:
await self.handler.on_exchange_third_party_invite_request(event_dict)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method doesnt return results anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm...so this is a bit tricky FederationHandler.on_exchange_third_party_invite_request always returns None, but it looks like the result of this is actually returned via FederationThirdPartyInviteExchangeServlet, so something is a bit funky here.

It looks like it should be just returning {} instead.

Copy link
Member Author

@clokep clokep Apr 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, actually FederationThirdPartyInviteExchangeServlet calls the handler, not here so that's unrelated.

:sigh: The above is actually wrong. The thing the code calls handler is actually FederationServer. 🤦

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just pointing to changing the method behaviour on this, i have no other context, but no worries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7e030a2 will stop using the returned value from this, which is always None.


async def check_server_matches_acl(self, server_name: str, room_id: str):
async def check_server_matches_acl(self, server_name: str, room_id: str) -> None:
"""Check if the given server is allowed by the server ACLs in the room

Args:
Expand Down Expand Up @@ -878,7 +876,7 @@ def __init__(self, hs: "HomeServer"):

def register_edu_handler(
self, edu_type: str, handler: Callable[[str, JsonDict], Awaitable[None]]
):
) -> None:
"""Sets the handler callable that will be used to handle an incoming
federation EDU of the given type.

Expand All @@ -897,7 +895,7 @@ def register_edu_handler(

def register_query_handler(
self, query_type: str, handler: Callable[[dict], Awaitable[JsonDict]]
):
) -> None:
"""Sets the handler callable that will be used to handle an incoming
federation query of the given type.

Expand All @@ -915,15 +913,17 @@ def register_query_handler(

self.query_handlers[query_type] = handler

def register_instance_for_edu(self, edu_type: str, instance_name: str):
def register_instance_for_edu(self, edu_type: str, instance_name: str) -> None:
"""Register that the EDU handler is on a different instance than master."""
self._edu_type_to_instance[edu_type] = [instance_name]

def register_instances_for_edu(self, edu_type: str, instance_names: List[str]):
def register_instances_for_edu(
self, edu_type: str, instance_names: List[str]
) -> None:
"""Register that the EDU handler is on multiple instances."""
self._edu_type_to_instance[edu_type] = instance_names

async def on_edu(self, edu_type: str, origin: str, content: dict):
async def on_edu(self, edu_type: str, origin: str, content: dict) -> None:
if not self.config.use_presence and edu_type == EduTypes.Presence:
return

Expand Down
4 changes: 2 additions & 2 deletions synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,8 @@ class FederationThirdPartyInviteExchangeServlet(BaseFederationServlet):
PATH = "/exchange_third_party_invite/(?P<room_id>[^/]*)"

async def on_PUT(self, origin, content, query, room_id):
content = await self.handler.on_exchange_third_party_invite_request(content)
return 200, content
await self.handler.on_exchange_third_party_invite_request(content)
return 200, {}


class FederationClientKeysQueryServlet(BaseFederationServlet):
Expand Down
Loading