mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Refactor FSM Storage methods input types to calm down MyPy. (#1683)
Some checks failed
Tests / tests (windows-latest, 3.13) (push) Has been cancelled
Tests / tests (windows-latest, 3.9) (push) Has been cancelled
Tests / pypy-tests (macos-latest, pypy3.10) (push) Has been cancelled
Tests / tests (macos-latest, 3.10) (push) Has been cancelled
Tests / tests (macos-latest, 3.11) (push) Has been cancelled
Tests / tests (macos-latest, 3.12) (push) Has been cancelled
Tests / tests (macos-latest, 3.13) (push) Has been cancelled
Tests / tests (macos-latest, 3.9) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.10) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.11) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.12) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.13) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.9) (push) Has been cancelled
Tests / tests (windows-latest, 3.10) (push) Has been cancelled
Tests / tests (windows-latest, 3.11) (push) Has been cancelled
Tests / tests (windows-latest, 3.12) (push) Has been cancelled
Tests / pypy-tests (macos-latest, pypy3.9) (push) Has been cancelled
Tests / pypy-tests (ubuntu-latest, pypy3.10) (push) Has been cancelled
Tests / pypy-tests (ubuntu-latest, pypy3.9) (push) Has been cancelled
Some checks failed
Tests / tests (windows-latest, 3.13) (push) Has been cancelled
Tests / tests (windows-latest, 3.9) (push) Has been cancelled
Tests / pypy-tests (macos-latest, pypy3.10) (push) Has been cancelled
Tests / tests (macos-latest, 3.10) (push) Has been cancelled
Tests / tests (macos-latest, 3.11) (push) Has been cancelled
Tests / tests (macos-latest, 3.12) (push) Has been cancelled
Tests / tests (macos-latest, 3.13) (push) Has been cancelled
Tests / tests (macos-latest, 3.9) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.10) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.11) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.12) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.13) (push) Has been cancelled
Tests / tests (ubuntu-latest, 3.9) (push) Has been cancelled
Tests / tests (windows-latest, 3.10) (push) Has been cancelled
Tests / tests (windows-latest, 3.11) (push) Has been cancelled
Tests / tests (windows-latest, 3.12) (push) Has been cancelled
Tests / pypy-tests (macos-latest, pypy3.9) (push) Has been cancelled
Tests / pypy-tests (ubuntu-latest, pypy3.10) (push) Has been cancelled
Tests / pypy-tests (ubuntu-latest, pypy3.9) (push) Has been cancelled
* 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` * Add 1683.feature.rst * Remove re-init in `DataNotDictLikeError`
This commit is contained in:
parent
afecf00f4a
commit
e011d103c0
9 changed files with 99 additions and 18 deletions
|
|
@ -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"}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue