Skip to content

refactor: eliminate type: ignore and extract AI helpers#34

Merged
ChanyaVRC merged 1 commit into
masterfrom
refactor/cleanup
May 4, 2026
Merged

refactor: eliminate type: ignore and extract AI helpers#34
ChanyaVRC merged 1 commit into
masterfrom
refactor/cleanup

Conversation

@ChanyaVRC

Copy link
Copy Markdown
Owner

Summary

  • Remove 54 # type: ignore[attr-defined] across all 9 cogs by adding a TYPE_CHECKING-gated from src.main import IdealBot import and changing bot: commands.Bot to bot: "IdealBot". Safe at runtime because from __future__ import annotations makes annotations lazy, and TYPE_CHECKING is False at runtime — no circular import.
  • Deduplicate _has_remote_llm() logic in main.py: the identical two-line bot_settings_db check appeared in both setup_hook and _reload_generator_poller; extracted as an async method.
  • Provider constants in generator.py: _PROVIDER_OPENAI/GEMINI/VLLM replace bare string literals in _resolve_llm and _generate_llm.
  • Extract generation helpers from the 130-line generate_sentence in local.py: _build_chat_messages(), _strip_generated_output(), _NEXT_TURN_MARKERS, _ASSISTANT_TURN_MARKERS; add Any return type to _build_cpu_generator/_build_gpu_generator.

Test plan

  • All 190 existing tests pass (pytest tests/ -x -q)
  • No # type: ignore comments remain in src/

…AI helpers

- Add TYPE_CHECKING-gated `from src.main import IdealBot` to all 9 cogs;
  change `bot: commands.Bot` to `bot: "IdealBot"` to remove 54 attr-defined
  suppressions without a runtime circular import
- Extract `_has_remote_llm()` method on IdealBot to remove duplicate
  bot_settings checks in setup_hook and _reload_generator_poller
- Define `_PROVIDER_OPENAI/GEMINI/VLLM` constants in generator.py to
  replace bare string literals
- Extract `_build_chat_messages()` and `_strip_generated_output()` helpers
  from the 130-line `generate_sentence`; define `_NEXT_TURN_MARKERS` and
  `_ASSISTANT_TURN_MARKERS` module constants
- Add `Any` return type annotations to `_build_cpu_generator` and
  `_build_gpu_generator`
@ChanyaVRC ChanyaVRC merged commit 64638c7 into master May 4, 2026
2 checks passed
@ChanyaVRC ChanyaVRC deleted the refactor/cleanup branch May 4, 2026 06:51
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