Упрощена и покрыта тестами логика Dispatcher.__ready()#51
Open
Olegt0rr wants to merge 4 commits intolove-apples:mainfrom
Open
Упрощена и покрыта тестами логика Dispatcher.__ready()#51Olegt0rr wants to merge 4 commits intolove-apples:mainfrom
Dispatcher.__ready()#51Olegt0rr wants to merge 4 commits intolove-apples:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Dispatcher.__ready() method to reduce its cyclomatic complexity from 11 to below the threshold of 10, as required by Ruff's C901 rule. The refactoring extracts logically separable operations into dedicated methods and utility functions while also adding comprehensive test coverage for these components.
Changes:
- Extracted command extraction logic from
Dispatcher.__ready()to new utility functionsextract_commands()andget_handler_info()inmaxapi/utils/commands.py - Split
Dispatcher.__ready()into smaller methods:_prepare_handlers()and_check_subscriptions() - Enabled C90 complexity checks globally in ruff configuration while adding temporary exceptions for files still requiring refactoring
- Reorganized utility tests from a single
tests/test_utils.pyfile into atests/test_utils/directory with separate files per module
Reviewed changes
Copilot reviewed 7 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| maxapi/dispatcher.py | Refactored __ready() method by extracting subscription checking and handler preparation logic into separate methods, reducing complexity |
| maxapi/utils/commands.py | New utility module containing extract_commands() and get_handler_info() functions for command extraction logic |
| pyproject.toml | Enabled C90 complexity checks globally, removed from ignore list, added per-file exceptions for files needing refactoring |
| tests/test_dispatcher.py | Added comprehensive tests for _prepare_handlers(), _check_subscriptions(), and __ready() methods |
| tests/test_utils/test_commands.py | New test file with comprehensive coverage for command extraction utilities |
| tests/test_utils/test_time_utils.py | New test file for time utility functions |
| tests/test_utils/test_keyboard_builder.py | Migrated from tests/test_utils.py, changed from class-based to function-based test organization |
| tests/test_utils.py | Removed (contents migrated to tests/test_utils/test_keyboard_builder.py) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ruff ругался на сложность метода
Dispatcher.__ready().Часть логически выделяемых действий я вынес в отдельные функции и методы, а также полностью покрыл их тестами, чтобы увеличить тестовое покрытие
DispatcherВ процессе рефакторинга удалось сделать незначительные улучшения: