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

Commit

Permalink
MSC2918: use attr.s instead of TypedDict
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Gliech <quentingliech@gmail.com>
  • Loading branch information
sandhose committed May 5, 2021
1 parent adc6eab commit 6963fe0
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple

from prometheus_client import Counter
from typing_extensions import TypedDict
import attr

from synapse import types
from synapse.api.constants import MAX_USERID_LENGTH, EventTypes, JoinRules, LoginType
Expand Down Expand Up @@ -56,15 +56,13 @@
["guest", "auth_provider"],
)

LoginDict = TypedDict(
"LoginDict",
{
"device_id": str,
"access_token": str,
"valid_until_ms": Optional[int],
"refresh_token": Optional[str],
},
)

@attr.s(frozen=True, slots=True)
class DeviceRegistrationResult:
device_id = attr.ib(type=str)
access_token = attr.ib(type=str)
valid_until_ms = attr.ib(type=Optional[int])
refresh_token = attr.ib(type=Optional[str])


class RegistrationHandler(BaseHandler):
Expand Down Expand Up @@ -710,10 +708,10 @@ async def register_device(
).inc()

return (
res["device_id"],
res["access_token"],
res["valid_until_ms"],
res["refresh_token"],
res.device_id,
res.access_token,
res.valid_until_ms,
res.refresh_token,
)

async def register_device_inner(
Expand All @@ -724,7 +722,7 @@ async def register_device_inner(
is_guest: bool = False,
is_appservice_ghost: bool = False,
should_issue_refresh_token: bool = False,
) -> LoginDict:
) -> DeviceRegistrationResult:
"""Helper for register_device
Does the bits that need doing on the main process. Not for use outside this
Expand Down Expand Up @@ -769,12 +767,12 @@ class and RegisterDeviceReplicationServlet.
refresh_token_id=refresh_token_id,
)

return {
"device_id": registered_device_id,
"access_token": access_token,
"valid_until_ms": valid_until_ms,
"refresh_token": refresh_token,
}
return DeviceRegistrationResult(
device_id=registered_device_id,
access_token=access_token,
valid_until_ms=valid_until_ms,
refresh_token=refresh_token,
)

async def post_registration_actions(
self, user_id: str, auth_result: dict, access_token: Optional[str]
Expand Down

0 comments on commit 6963fe0

Please sign in to comment.