Refactor FSM Storage methods input types to calm down MyPy.#1683
Refactor FSM Storage methods input types to calm down MyPy.#1683JrooTJunior merged 3 commits intoaiogram:dev-3.xfrom
Conversation
- `FSMContext.set_data` - `FSMContext.update_data` - `BaseStorage.set_data` - `BaseStorage.update_data` - `BaseStorage`'s child methods - `SceneWizard.set_data` - `SceneWizard.update_data`
✔️ Changelog found.Thank you for adding a description of the changes |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors methods’ input types across FSM storage and scene modules to address MyPy issues while adding runtime validation for dict-like data. Key changes include updating type annotations from Dict[str, Any] to Mapping[str, Any], adding explicit type checks that raise DataNotDictLikeError, and extending test coverage for these new validations.
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_fsm/storage/test_storages.py | Added tests using TypedDict and validation for non-dict data types |
| aiogram/fsm/storage/redis.py | Updated set_data signature and added a runtime check for dict types |
| aiogram/fsm/storage/mongo.py | Updated set_data and update_data signatures with runtime validations |
| aiogram/fsm/storage/memory.py | Updated set_data signature with an added type check |
| aiogram/fsm/storage/base.py | Adjusted abstract type hints for data parameters |
| aiogram/fsm/scene.py | Updated scene methods’ parameter annotations and documentation |
| aiogram/fsm/context.py | Updated context methods to use Mapping for set_data and update_data |
| aiogram/exceptions.py | Added DataNotDictLikeError for invalid data inputs |
Files not reviewed (1)
- CHANGES/1683.feature.rst: Language not supported
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the input types for FSM storage methods to calm down MyPy and adds runtime validations for data passed to these methods. Key changes include updating function signatures from Dict[str, Any] to Mapping[str, Any] for storage methods, adding runtime checks to ensure that data is a dict, and updating tests and exceptions accordingly.
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_fsm/storage/test_storages.py | Added tests to cover TypedDict inputs and exception handling for invalid data. |
| aiogram/fsm/storage/redis.py | Updated type hints for set_data and added a runtime check to enforce dict type. |
| aiogram/fsm/storage/mongo.py | Updated type hints and added a runtime check in set_data to verify dict type. |
| aiogram/fsm/storage/memory.py | Updated set_data signature to accept Mapping and enforced a dict copy after check. |
| aiogram/fsm/storage/base.py | Updated abstract methods for set_data and update_data to accept Mapping. |
| aiogram/fsm/scene.py & aiogram/fsm/context.py | Updated method signatures to use Mapping where applicable. |
| aiogram/exceptions.py | Introduced DataNotDictLikeError for enforcing dict-like input validations. |
Files not reviewed (1)
- CHANGES/1683.feature.rst: Language not supported
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev-3.x #1683 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 568 568
Lines 13341 13351 +10
=========================================
+ Hits 13341 13351 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
01b98d0 to
19250ee
Compare
#1682
Description
Refactor FSM Storage methods input types to calm down MyPy.
Refactored:
FSMContext.set_dataFSMContext.update_dataBaseStorage.set_dataBaseStorage.update_dataBaseStorage's child methodsSceneWizard.set_dataSceneWizard.update_dataType of change
Please delete options that are not relevant.
How Has This Been Tested?
1 test edited to cover new code
Checklist: