-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Create a mypy plugin for replication class methods #8828
Description
Replication servlet classes, such as ReplicationRemoteJoinRestServlet, ReplicationUserDevicesResyncRestServlet etc. each have _serialize_payload and _handle_request methods. Traditionally we haven't added typing to these methods as it breaks mypy for two reasons:
- Their signatures differ from the base methods in
ReplicationEndpoint. - Their signatures differ from
send_request, which is what is returned bymake_clientand what is run when making a replication request.
If types are added to any instance of _serialize_payload or _handle_request, mypy will complain about this discrepancy, and thus an # type: ignore has typically been put on the method signature in order to avoid this:
synapse/synapse/replication/http/membership.py
Lines 55 to 62 in 377673d
| @staticmethod | |
| async def _serialize_payload( # type: ignore | |
| requester: Requester, | |
| room_id: str, | |
| user_id: str, | |
| remote_room_hosts: List[str], | |
| content: JsonDict, | |
| ) -> JsonDict: |
A better solution is to write a mypy plugin, much like we already have for cache functions to properly check the types and remove the need to ignore them.
Note that this issue grew out of a discussion here: #8809 (comment)