Skip to content

Comments

Упрощена и покрыта тестами логика Dispatcher.__ready()#51

Open
Olegt0rr wants to merge 4 commits intolove-apples:mainfrom
Olegt0rr:chore/refactor-dispatchers-ready
Open

Упрощена и покрыта тестами логика Dispatcher.__ready()#51
Olegt0rr wants to merge 4 commits intolove-apples:mainfrom
Olegt0rr:chore/refactor-dispatchers-ready

Conversation

@Olegt0rr
Copy link
Contributor

@Olegt0rr Olegt0rr commented Feb 22, 2026

Ruff ругался на сложность метода Dispatcher.__ready().

C901 `__ready` is too complex (11 > 10)

Часть логически выделяемых действий я вынес в отдельные функции и методы, а также полностью покрыл их тестами, чтобы увеличить тестовое покрытие Dispatcher

В процессе рефакторинга удалось сделать незначительные улучшения:

  • разделена терминология регистрации и подготовке обработчиков событий
  • информацию о хендлере теперь получаем 1 раз, а не в цикле для каждой команды
  • при отсутствии описания, но наличии метки commands_info не пытаемся передать в API пустую строку
  • включена проверка сложности для новых доработок (но добавлены временные исключения с todo)

Copilot AI review requested due to automatic review settings February 22, 2026 08:37
@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 functions extract_commands() and get_handler_info() in maxapi/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.py file into a tests/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.

Olegt0rr and others added 2 commits February 22, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant