Skip to content

fix: restore star context typing#8659

Merged
Soulter merged 1 commit into
masterfrom
codex/fix-star-context-typing
Jun 7, 2026
Merged

fix: restore star context typing#8659
Soulter merged 1 commit into
masterfrom
codex/fix-star-context-typing

Conversation

@Soulter
Copy link
Copy Markdown
Member

@Soulter Soulter commented Jun 7, 2026

Summary

  • remove the local _ContextLike protocol from Star
  • type Star.context and Star.init with the real Context under TYPE_CHECKING
  • keep runtime imports unchanged to avoid reintroducing the circular dependency fixed by fix: resolve pipeline and star import cycles #5353

Tests

  • uv run pytest tests/unit/test_star_base.py
  • uv run ruff format astrbot/core/star/base.py
  • uv run ruff check astrbot/core/star/base.py

Summary by Sourcery

Restore Star context attribute and constructor typing to use the real Context type while preserving existing runtime import behavior.

Bug Fixes:

  • Align Star.context and Star.init type annotations with the actual Context type to prevent incorrect or incomplete typing of the Star context.

Enhancements:

  • Remove the local _ContextLike protocol in favor of the concrete Context type under TYPE_CHECKING for clearer and more accurate static typing.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels Jun 7, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors astrbot/core/star/base.py by replacing the local _ContextLike Protocol with the concrete Context class, which is imported conditionally under TYPE_CHECKING to prevent circular imports. The context attribute on the Star class is now explicitly typed with Context. There are no review comments, and I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Since Context is only imported under TYPE_CHECKING, make sure this module either uses from __future__ import annotations or changes context: Context / def __init__(..., context: Context, ...) to use string annotations (e.g., "Context") to avoid a NameError at runtime.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since `Context` is only imported under `TYPE_CHECKING`, make sure this module either uses `from __future__ import annotations` or changes `context: Context` / `def __init__(..., context: Context, ...)` to use string annotations (e.g., `"Context"`) to avoid a `NameError` at runtime.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Soulter Soulter merged commit 8f5178d into master Jun 7, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant