Skip to content

chore: reduce pyright type errors#8197

Open
Dt8333 wants to merge 2 commits into
AstrBotDevs:masterfrom
Dt8333:chore-pyright-fix
Open

chore: reduce pyright type errors#8197
Dt8333 wants to merge 2 commits into
AstrBotDevs:masterfrom
Dt8333:chore-pyright-fix

Conversation

@Dt8333
Copy link
Copy Markdown
Member

@Dt8333 Dt8333 commented May 15, 2026

Reduce Pyright type-checking errors.

Modifications / 改动点

Adjusted the execution order of certain sections and added conditional checks to allow Pyright to correctly narrow types.
Corrected several declarations.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Improve type safety and static analysis compliance across core components to reduce Pyright errors.

Bug Fixes:

  • Normalize process exit codes to integers when possible before inferring defaults in CUA payload handling.
  • Avoid calling methods or callbacks on potentially missing attributes by checking callability and nullability in computer adapter and DingTalk client startup logic.
  • Guard plugin update repo downloads so they are only attempted when a repository URL is available.
  • Use SQLAlchemy column expressions consistently in SQLite queries to avoid type and expression issues.
  • Ensure message posting APIs can return an absent message result by widening the return type.

Enhancements:

  • Add overloads and stricter type annotations for builtin tool registration and various core helpers to satisfy Pyright.
  • Refine normalization of MCP schema properties and content block typing in computer tools for clearer and safer data handling.
  • Tighten typing for async tool executor iteration, command group component construction, and platform manager protocols to better reflect actual usage.

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:

  • In first_text, consider narrowing the except Exception around int(exit_code) to except (TypeError, ValueError) so that unexpected errors in exit_code handling are not silently swallowed.
  • The task.add_done_callback lambda in the DingTalk adapter relies on the mutable self._shutdown_event attribute; it might be clearer and safer to capture the event in a local variable (or a small helper function) before defining the callback to avoid potential races if the attribute is reassigned.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `first_text`, consider narrowing the `except Exception` around `int(exit_code)` to `except (TypeError, ValueError)` so that unexpected errors in `exit_code` handling are not silently swallowed.
- The `task.add_done_callback` lambda in the DingTalk adapter relies on the mutable `self._shutdown_event` attribute; it might be clearer and safer to capture the event in a local variable (or a small helper function) before defining the callback to avoid potential races if the attribute is reassigned.

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.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels May 15, 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 introduces several refactorings and robustness improvements across the codebase. Key changes include safer attribute access and type casting in the CUA booter, updated SQLAlchemy query syntax using col() for column references, and refined type hints for MCP clients and tool registries. Additionally, the PR adds safety checks for event callbacks in the DingTalk adapter and streamlines logic in the Anthropic provider and plugin updater. There are no review comments, and I have no feedback to provide.

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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant