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

Commit 6963fe0

Browse files
committed
MSC2918: use attr.s instead of TypedDict
Signed-off-by: Quentin Gliech <[email protected]>
1 parent adc6eab commit 6963fe0

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

synapse/handlers/register.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple
2020

2121
from prometheus_client import Counter
22-
from typing_extensions import TypedDict
22+
import attr
2323

2424
from synapse import types
2525
from synapse.api.constants import MAX_USERID_LENGTH, EventTypes, JoinRules, LoginType
@@ -56,15 +56,13 @@
5656
["guest", "auth_provider"],
5757
)
5858

59-
LoginDict = TypedDict(
60-
"LoginDict",
61-
{
62-
"device_id": str,
63-
"access_token": str,
64-
"valid_until_ms": Optional[int],
65-
"refresh_token": Optional[str],
66-
},
67-
)
59+
60+
@attr.s(frozen=True, slots=True)
61+
class DeviceRegistrationResult:
62+
device_id = attr.ib(type=str)
63+
access_token = attr.ib(type=str)
64+
valid_until_ms = attr.ib(type=Optional[int])
65+
refresh_token = attr.ib(type=Optional[str])
6866

6967

7068
class RegistrationHandler(BaseHandler):
@@ -710,10 +708,10 @@ async def register_device(
710708
).inc()
711709

712710
return (
713-
res["device_id"],
714-
res["access_token"],
715-
res["valid_until_ms"],
716-
res["refresh_token"],
711+
res.device_id,
712+
res.access_token,
713+
res.valid_until_ms,
714+
res.refresh_token,
717715
)
718716

719717
async def register_device_inner(
@@ -724,7 +722,7 @@ async def register_device_inner(
724722
is_guest: bool = False,
725723
is_appservice_ghost: bool = False,
726724
should_issue_refresh_token: bool = False,
727-
) -> LoginDict:
725+
) -> DeviceRegistrationResult:
728726
"""Helper for register_device
729727
730728
Does the bits that need doing on the main process. Not for use outside this
@@ -769,12 +767,12 @@ class and RegisterDeviceReplicationServlet.
769767
refresh_token_id=refresh_token_id,
770768
)
771769

772-
return {
773-
"device_id": registered_device_id,
774-
"access_token": access_token,
775-
"valid_until_ms": valid_until_ms,
776-
"refresh_token": refresh_token,
777-
}
770+
return DeviceRegistrationResult(
771+
device_id=registered_device_id,
772+
access_token=access_token,
773+
valid_until_ms=valid_until_ms,
774+
refresh_token=refresh_token,
775+
)
778776

779777
async def post_registration_actions(
780778
self, user_id: str, auth_result: dict, access_token: Optional[str]

0 commit comments

Comments
 (0)