mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
feat(storage-api): remove default param for get_state methods.
This commit is contained in:
parent
7f8004f5a1
commit
00e3543cc3
3 changed files with 6 additions and 7 deletions
|
|
@ -33,8 +33,8 @@ class CurrentUserContext(Generic[StorageDataT]):
|
|||
self.storage = storage
|
||||
self.key = key_maker(chat_id, user_id)
|
||||
|
||||
async def get_state(self, default: Optional[str] = None) -> Optional[str]:
|
||||
return await self.storage.get_state(self.key, default=default)
|
||||
async def get_state(self) -> Optional[str]:
|
||||
return await self.storage.get_state(self.key)
|
||||
|
||||
async def get_data(self) -> StorageDataT:
|
||||
return await self.storage.get_data(self.key)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ _DataT = TypeVar("_DataT")
|
|||
|
||||
|
||||
class BaseStorage(Generic[_DataT]):
|
||||
async def get_state(self, key: str, default: Optional[str] = None) -> Optional[str]:
|
||||
async def get_state(self, key: str) -> Optional[str]:
|
||||
raise NotImplementedError
|
||||
|
||||
async def set_state(self, key: str, state: Optional[str]) -> None:
|
||||
|
|
|
|||
|
|
@ -13,19 +13,18 @@ class _UserStorageMetaData(TypedDict):
|
|||
|
||||
class DictStorage(BaseStorage[Dict[str, Any]]):
|
||||
"""
|
||||
In-memory based states storage.
|
||||
This type of storage is not recommended for usage in bots, because you will lost all states after restarting.
|
||||
Python dictionary data structure based state storage.
|
||||
Not the most persistent storage, not recommended for in-production environments.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
# note: we can use TypedDict for Dict flat value
|
||||
self.data: Dict[str, _UserStorageMetaData] = {}
|
||||
|
||||
def resolve_address(self, key: str) -> None:
|
||||
if key not in self.data:
|
||||
self.data[key] = {"state": None, "data": {}}
|
||||
|
||||
async def get_state(self, key: str, default: Optional[str] = None) -> Optional[str]:
|
||||
async def get_state(self, key: str) -> Optional[str]:
|
||||
self.resolve_address(key)
|
||||
return self.data[key]["state"]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue