Skip to content

fix: postpone jmcomic type annotation evaluation - #62

Open
zouyonghe wants to merge 2 commits into
GEMILUXVII:mainfrom
zouyonghe:main
Open

fix: postpone jmcomic type annotation evaluation#62
zouyonghe wants to merge 2 commits into
GEMILUXVII:mainfrom
zouyonghe:main

Conversation

@zouyonghe

@zouyonghe zouyonghe commented Jun 1, 2026

Copy link
Copy Markdown

Avoid import-time TypeError when jmcomic is absent by postponing evaluation of JmOption | None annotations. This lets the plugin import cleanly and report jmcomic as unavailable at runtime instead of failing during module import.

Summary by Sourcery

Bug Fixes:

  • Prevent import-time TypeError when jmcomic is missing by postponing evaluation of JmOption-related type annotations.

@sourcery-ai

sourcery-ai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Defers evaluation of jmcomic-related type annotations so the plugin imports cleanly when jmcomic is not installed, shifting failures from import-time to runtime availability checks.

File-Level Changes

Change Details Files
Delay evaluation of jmcomic-dependent type annotations to avoid import-time errors when jmcomic is missing.
  • Adjusted type hints that referenced JmOption so they are evaluated lazily instead of at module import time
  • Ensured jmcomic absence is handled gracefully at runtime, allowing the plugin to report unavailability instead of raising TypeError during import
core/base/client.py
core/base/config.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


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.

@Coloynle

Coloynle commented Jun 9, 2026

Copy link
Copy Markdown

[2026-06-09 04:34:36.902] [Core]
[INFO]
[star.star_manager:953]: Loading plugin jm_cosmos2 ...
[2026-06-09 04:34:37.096] [Core]
[ERRO]
[v4.25.5] [star.star_manager:966]: Traceback (most recent call last):
File "/AstrBot/astrbot/core/star/star_manager.py", line 957, in load
module = await self._import_plugin_with_dependency_recovery(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/AstrBot/astrbot/core/star/star_manager.py", line 434, in _import_plugin_with_dependency_recovery
return import(path, fromlist=[module_str])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/AstrBot/data/plugins/jm_cosmos2/main.py", line 14, in
from .core import (
File "/AstrBot/data/plugins/jm_cosmos2/core/init.py", line 9, in
from .auth import JMAuthManager
File "/AstrBot/data/plugins/jm_cosmos2/core/auth.py", line 11, in
from .base import JMClientMixin, JMConfigManager
File "/AstrBot/data/plugins/jm_cosmos2/core/base/init.py", line 7, in
from .client import JMClientMixin
File "/AstrBot/data/plugins/jm_cosmos2/core/base/client.py", line 12, in
from .config import JMConfigManager
File "/AstrBot/data/plugins/jm_cosmos2/core/base/config.py", line 18, in
class JMConfigManager:
File "/AstrBot/data/plugins/jm_cosmos2/core/base/config.py", line 179, in JMConfigManager
def create_jm_option(self) -> JmOption | None:
~~~~~~~~~^~~~~~
TypeError: unsupported operand type(s) for |: 'NoneType' and 'NoneType'
[2026-06-09 04:34:37.097] [Core]
[ERRO]
[v4.25.5] [star.star_manager:967]: 插件 jm_cosmos2 导入失败。原因:unsupported operand type(s) for |: 'NoneType' and 'NoneType'

这个提交应该能修复这个问题

@zouyonghe

Copy link
Copy Markdown
Author

[2026-06-09 04:34:36.902] [Core] [INFO] [star.star_manager:953]: Loading plugin jm_cosmos2 ... [2026-06-09 04:34:37.096] [Core] [ERRO] [v4.25.5] [star.star_manager:966]: Traceback (most recent call last): File "/AstrBot/astrbot/core/star/star_manager.py", line 957, in load module = await self._import_plugin_with_dependency_recovery( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/AstrBot/astrbot/core/star/star_manager.py", line 434, in _import_plugin_with_dependency_recovery return import(path, fromlist=[module_str]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/AstrBot/data/plugins/jm_cosmos2/main.py", line 14, in from .core import ( File "/AstrBot/data/plugins/jm_cosmos2/core/init.py", line 9, in from .auth import JMAuthManager File "/AstrBot/data/plugins/jm_cosmos2/core/auth.py", line 11, in from .base import JMClientMixin, JMConfigManager File "/AstrBot/data/plugins/jm_cosmos2/core/base/init.py", line 7, in from .client import JMClientMixin File "/AstrBot/data/plugins/jm_cosmos2/core/base/client.py", line 12, in from .config import JMConfigManager File "/AstrBot/data/plugins/jm_cosmos2/core/base/config.py", line 18, in class JMConfigManager: File "/AstrBot/data/plugins/jm_cosmos2/core/base/config.py", line 179, in JMConfigManager def create_jm_option(self) -> JmOption | None: ~~~~~~~~~^~~~~~ TypeError: unsupported operand type(s) for |: 'NoneType' and 'NoneType' [2026-06-09 04:34:37.097] [Core] [ERRO] [v4.25.5] [star.star_manager:967]: 插件 jm_cosmos2 导入失败。原因:unsupported operand type(s) for |: 'NoneType' and 'NoneType'

这个提交应该能修复这个问题

还在等合并

@GEMILUXVII

Copy link
Copy Markdown
Owner

2.6.7应该不会报这个错误了

@Coloynle

Copy link
Copy Markdown

会报的,我是用 docker的,镜像更新后,重新创建容器,这个插件会报这个错

@Coloynle

Copy link
Copy Markdown

我有个定时更新镜像的任务,只要更新一次就报一次,不是之前那个名的问题,from future import annotations这个应该能解决

@zouyonghe

Copy link
Copy Markdown
Author

最新版本依然加载失败

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.

3 participants