1919from typing import TYPE_CHECKING , Iterable , List , Optional , Tuple
2020
2121from prometheus_client import Counter
22- from typing_extensions import TypedDict
22+ import attr
2323
2424from synapse import types
2525from synapse .api .constants import MAX_USERID_LENGTH , EventTypes , JoinRules , LoginType
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
7068class 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