Mark key parameters as positional-only in async getter lock methods

This commit is contained in:
Tulir Asokan
2022-08-14 12:49:45 +03:00
parent c4c225343c
commit 910a681f4b
3 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -3229,7 +3229,7 @@ class Portal(DBPortal, BasePortal):
@classmethod @classmethod
@async_getter_lock @async_getter_lock
async def get_by_mxid(cls, mxid: RoomID) -> Portal | None: async def get_by_mxid(cls, mxid: RoomID, /) -> Portal | None:
try: try:
return cls.by_mxid[mxid] return cls.by_mxid[mxid]
except KeyError: except KeyError:
@@ -3270,7 +3270,7 @@ class Portal(DBPortal, BasePortal):
@classmethod @classmethod
@async_getter_lock @async_getter_lock
async def get_by_tgid( async def get_by_tgid(
cls, tgid: TelegramID, *, tg_receiver: TelegramID | None = None, peer_type: str = None cls, tgid: TelegramID, /, *, tg_receiver: TelegramID | None = None, peer_type: str = None
) -> Portal | None: ) -> Portal | None:
if peer_type == "user" and tg_receiver is None: if peer_type == "user" and tg_receiver is None:
raise ValueError('tg_receiver is required when peer_type is "user"') raise ValueError('tg_receiver is required when peer_type is "user"')
+2 -2
View File
@@ -406,7 +406,7 @@ class Puppet(DBPuppet, BasePuppet):
@classmethod @classmethod
@async_getter_lock @async_getter_lock
async def get_by_tgid( async def get_by_tgid(
cls, tgid: TelegramID, *, create: bool = True, is_channel: bool = False cls, tgid: TelegramID, /, *, create: bool = True, is_channel: bool = False
) -> Puppet | None: ) -> Puppet | None:
if tgid is None: if tgid is None:
return None return None
@@ -459,7 +459,7 @@ class Puppet(DBPuppet, BasePuppet):
@classmethod @classmethod
@async_getter_lock @async_getter_lock
async def get_by_custom_mxid(cls, mxid: UserID) -> Puppet | None: async def get_by_custom_mxid(cls, mxid: UserID, /) -> Puppet | None:
try: try:
return cls.by_custom_mxid[mxid] return cls.by_custom_mxid[mxid]
except KeyError: except KeyError:
+2 -2
View File
@@ -711,7 +711,7 @@ class User(DBUser, AbstractUser, BaseUser):
@classmethod @classmethod
@async_getter_lock @async_getter_lock
async def get_by_mxid( async def get_by_mxid(
cls, mxid: UserID, *, check_db: bool = True, create: bool = True cls, mxid: UserID, /, *, check_db: bool = True, create: bool = True
) -> User | None: ) -> User | None:
if not mxid or pu.Puppet.get_id_from_mxid(mxid) or mxid == cls.az.bot_mxid: if not mxid or pu.Puppet.get_id_from_mxid(mxid) or mxid == cls.az.bot_mxid:
return None return None
@@ -739,7 +739,7 @@ class User(DBUser, AbstractUser, BaseUser):
@classmethod @classmethod
@async_getter_lock @async_getter_lock
async def get_by_tgid(cls, tgid: TelegramID) -> User | None: async def get_by_tgid(cls, tgid: TelegramID, /) -> User | None:
try: try:
return cls.by_tgid[tgid] return cls.by_tgid[tgid]
except KeyError: except KeyError: