Skip to content

Refactor section classes to factory functions#7

Merged
andreisavu merged 1 commit intomainfrom
claude/refactor-sections-to-functions-lRFGn
Jan 26, 2026
Merged

Refactor section classes to factory functions#7
andreisavu merged 1 commit intomainfrom
claude/refactor-sections-to-functions-lRFGn

Conversation

@andreisavu
Copy link
Member

Summary

Convert section classes (QuestionSection, GameRulesSection, HintsSection, LuckyDiceSection) to factory functions (build_question_section(), build_game_rules_section(), build_hints_section(), build_lucky_dice_section()). This simplifies the API by eliminating unnecessary class instantiation boilerplate while maintaining the same functionality.

Key Changes

  • Converted 4 section classes to factory functions in src/trivia_agent/sections.py:

    • QuestionSectionbuild_question_section()
    • GameRulesSectionbuild_game_rules_section()
    • HintsSectionbuild_hints_section()
    • LuckyDiceSectionbuild_lucky_dice_section()
  • Updated documentation to reflect the factory function pattern:

    • Module docstring now references factory functions instead of classes
    • Updated usage examples to show build_*() calls instead of class instantiation
    • Updated docstrings to describe what each factory function creates
  • Updated all imports and usages across the codebase:

    • src/trivia_agent/worker.py: Updated imports and instantiation calls
    • tests/trivia_agent/test_sections.py: Updated test class names and function calls
    • tests/trivia_agent/test_worker.py: Updated imports and test class names
  • Minor improvements:

    • Changed type ignore comment from type: ignore[attr-defined] to pyright: ignore[reportUnknownVariableType] for better clarity
    • Moved dice_policy definition outside the function in build_lucky_dice_section() for clarity

Implementation Details

Each factory function returns a fully configured MarkdownSection instance with all necessary parameters (title, key, template, tools, policies, etc.). This approach:

  • Reduces cognitive overhead by eliminating class definitions with __init__ methods
  • Makes the code more functional and easier to test
  • Maintains full backward compatibility in terms of functionality
  • Simplifies the API surface for users of the module

Convert QuestionSection, GameRulesSection, HintsSection, and LuckyDiceSection
from class-based definitions to factory functions (build_question_section,
build_game_rules_section, build_hints_section, build_lucky_dice_section).
This simplifies the code by directly returning configured MarkdownSection
instances rather than creating thin wrapper subclasses.

https://claude.ai/code/session_01VcXtbqjLRs8dMZM5y1Fbi1
@andreisavu
Copy link
Member Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@andreisavu andreisavu merged commit bc53808 into main Jan 26, 2026
1 check passed
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.

2 participants