Fix type hints

This commit is contained in:
Arthur Khachaturov 2024-10-22 02:14:21 +03:00
parent af20bed749
commit 8fc682b3f4
No known key found for this signature in database
GPG key ID: CAC2B7EB6DF45D55
6 changed files with 17 additions and 8 deletions

View file

@ -21,12 +21,12 @@ class FSMContext:
return await self.storage.get_data(key=self.key)
@overload
async def get_value(self, key: str) -> Any | None: ...
async def get_value(self, key: str) -> Optional[Any]: ...
@overload
async def get_value(self, key: str, default: Any) -> Any: ...
async def get_value(self, key, default=None):
async def get_value(self, key: str, default: Optional[Any] = None) -> Optional[Any]:
return await self.storage.get_value(storage_key=self.key, dict_key=key, default=default)
async def update_data(

View file

@ -595,7 +595,7 @@ class SceneWizard:
"""
pass
async def get_value(self, key, default=None):
async def get_value(self, key: str, default: Optional[Any] = None) -> Optional[Any]:
return await self.state.get_value(key, default)
async def update_data(

View file

@ -145,7 +145,6 @@ class BaseStorage(ABC):
pass
@overload
@abstractmethod
async def get_value(self, storage_key: StorageKey, dict_key: str) -> Optional[Any]:
"""
Get single value from data by key
@ -157,7 +156,6 @@ class BaseStorage(ABC):
pass
@overload
@abstractmethod
async def get_value(self, storage_key: StorageKey, dict_key: str, default: Any) -> Any:
"""
Get single value from data by key
@ -169,6 +167,11 @@ class BaseStorage(ABC):
"""
pass
@abstractmethod
async def get_value(
self, storage_key: StorageKey, dict_key: str, default: Optional[Any] = None
) -> Optional[Any]: ...
async def update_data(self, key: StorageKey, data: Dict[str, Any]) -> Dict[str, Any]:
"""
Update date in the storage for key (like dict.update)

View file

@ -56,7 +56,9 @@ class MemoryStorage(BaseStorage):
@overload
async def get_value(self, storage_key: StorageKey, dict_key: str, default: Any) -> Any: ...
async def get_value(self, storage_key, dict_key: str, default=None):
async def get_value(
self, storage_key: StorageKey, dict_key: str, default: Optional[Any] = None
) -> Optional[Any]:
return copy(self.storage[storage_key].data.get(dict_key, default))

View file

@ -121,7 +121,9 @@ class MongoStorage(BaseStorage):
@overload
async def get_value(self, storage_key: StorageKey, dict_key: str, default: Any) -> Any: ...
async def get_value(self, storage_key, dict_key, default=None):
async def get_value(
self, storage_key: StorageKey, dict_key: str, default: Optional[Any] = None
) -> Optional[Any]:
return (await self.get_data(storage_key)).get(dict_key, default)
async def update_data(self, key: StorageKey, data: Dict[str, Any]) -> Dict[str, Any]:

View file

@ -138,7 +138,9 @@ class RedisStorage(BaseStorage):
@overload
async def get_value(self, storage_key: StorageKey, dict_key: str, default: Any) -> Any: ...
async def get_value(self, storage_key, dict_key, default=None):
async def get_value(
self, storage_key: StorageKey, dict_key: str, default: Optional[Any] = None
) -> Optional[Any]:
return (await self.get_data(storage_key)).get(dict_key, default)