Refactor methods input types to calm down MyPy.

- `FSMContext.set_data`
- `FSMContext.update_data`
- `BaseStorage.set_data`
- `BaseStorage.update_data`
- `BaseStorage`'s child methods
- `SceneWizard.set_data`
- `SceneWizard.update_data`
This commit is contained in:
andrew000 2025-04-28 10:53:42 +03:00
parent 482629ac18
commit 370d1444f6
No known key found for this signature in database
GPG key ID: D332A306AAA27181
8 changed files with 91 additions and 18 deletions

View file

@ -1,5 +1,8 @@
from typing import TypedDict
import pytest
from aiogram.exceptions import DataNotDictLikeError
from aiogram.fsm.storage.base import BaseStorage, StorageKey
@ -44,6 +47,21 @@ class TestStorages:
== "baz"
)
class CustomTypedDict(TypedDict, total=False):
foo: str
bar: str
await storage.set_data(key=storage_key, data=CustomTypedDict(foo="bar", bar="baz"))
assert await storage.get_data(key=storage_key) == {"foo": "bar", "bar": "baz"}
assert await storage.get_value(storage_key=storage_key, dict_key="foo") == "bar"
assert (
await storage.get_value(storage_key=storage_key, dict_key="foo", default="baz")
== "bar"
)
with pytest.raises(DataNotDictLikeError):
await storage.set_data(key=storage_key, data=())
async def test_update_data(self, storage: BaseStorage, storage_key: StorageKey):
assert await storage.get_data(key=storage_key) == {}
assert await storage.update_data(key=storage_key, data={"foo": "bar"}) == {"foo": "bar"}