-
Notifications
You must be signed in to change notification settings - Fork 52
support validator null stub db and config access #730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -630,16 +630,69 @@ async def _return_self(): | |||||||||||
|
|
||||||||||||
| return _return_self().__await__() | ||||||||||||
|
|
||||||||||||
| async def __aenter__(self) -> "NullStub": | ||||||||||||
| return self | ||||||||||||
|
|
||||||||||||
| async def __aexit__(self, exc_type, exc, tb) -> bool: | ||||||||||||
| del exc_type, exc, tb | ||||||||||||
| return False | ||||||||||||
|
|
||||||||||||
| def get(self, key=None, default=None): | ||||||||||||
| del key | ||||||||||||
| return default | ||||||||||||
|
Comment on lines
+640
to
+642
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better code quality and maintainability, it's good to add type hints. Also, for unused arguments, it's more idiomatic in Python to prefix them with an underscore (
Suggested change
|
||||||||||||
|
|
||||||||||||
| def pop(self, key=None, default=None): | ||||||||||||
| del key | ||||||||||||
| return default | ||||||||||||
|
Comment on lines
+644
to
+646
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better code quality and maintainability, it's good to add type hints. Also, for unused arguments, it's more idiomatic in Python to prefix them with an underscore (
Suggested change
|
||||||||||||
|
|
||||||||||||
| def __iter__(self): | ||||||||||||
| return iter(()) | ||||||||||||
|
|
||||||||||||
| def __bool__(self) -> bool: | ||||||||||||
| return False | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class DummyConfig(dict): | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): Consider simplifying DummyConfig’s special behaviors and making DummyContext’s config/path accessors more explicit and side‑effect free to reduce hidden magic. You can keep the new behavior but reduce the “magic” in two focused ways: 1. Simplify
|
||||||||||||
| def __init__(self, initial=None) -> None: | ||||||||||||
| super().__init__(initial or {}) | ||||||||||||
|
|
||||||||||||
| def __missing__(self, key): | ||||||||||||
| del key | ||||||||||||
| return NullStub() | ||||||||||||
|
|
||||||||||||
| def __getattr__(self, name: str): | ||||||||||||
| return self[name] | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class DummyContext: | ||||||||||||
| def __init__(self) -> None: | ||||||||||||
| self._star_manager = None | ||||||||||||
| self._astrbot_root = Path(os.environ.get("ASTRBOT_ROOT", Path.cwd())).resolve() | ||||||||||||
| self._data_root = self._astrbot_root / "data" | ||||||||||||
| self._plugin_data_dir = self._data_root / "plugin_data" | ||||||||||||
| self._config = DummyConfig( | ||||||||||||
| { | ||||||||||||
| "wake_prefix": [], | ||||||||||||
| "dashboard": DummyConfig(), | ||||||||||||
| "admins_id": [], | ||||||||||||
| "admin_ids": [], | ||||||||||||
| "platform_settings": DummyConfig( | ||||||||||||
| { | ||||||||||||
| "aiocqhttp": {}, | ||||||||||||
| "qqofficial": {}, | ||||||||||||
| "telegram": {}, | ||||||||||||
| "gewechat": {}, | ||||||||||||
| "wechatpadpro": {}, | ||||||||||||
| } | ||||||||||||
| ), | ||||||||||||
| "data_dir": str(self._data_root), | ||||||||||||
| } | ||||||||||||
| ) | ||||||||||||
| self.config = self._config | ||||||||||||
|
|
||||||||||||
| def _ensure_plugin_data_dir(self) -> Path: | ||||||||||||
| self._plugin_data_dir.mkdir(parents=True, exist_ok=True) | ||||||||||||
| return self._plugin_data_dir | ||||||||||||
|
|
||||||||||||
| def get_all_stars(self): | ||||||||||||
| try: | ||||||||||||
|
|
@@ -669,6 +722,16 @@ def register_llm_tool(self, name: str, func_args, desc: str, func_obj) -> None: | |||||||||||
| def unregister_llm_tool(self, name: str) -> None: | ||||||||||||
| del name | ||||||||||||
|
|
||||||||||||
| def get_config(self, umo: str | None = None): | ||||||||||||
| del umo | ||||||||||||
| return self._config | ||||||||||||
|
|
||||||||||||
| def get_context_config(self): | ||||||||||||
| return self.get_config() | ||||||||||||
|
|
||||||||||||
| def get_data_dir(self) -> str: | ||||||||||||
| return str(self._ensure_plugin_data_dir()) | ||||||||||||
|
|
||||||||||||
| def __getattr__(self, name: str) -> NullStub: | ||||||||||||
| del name | ||||||||||||
| return NullStub() | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better code quality and maintainability, it's good to add type hints to arguments. Also, for unused arguments, it's more idiomatic in Python to prefix them with an underscore (
_) rather than usingdel, as recommended by style guides like PEP 8. Since types from thetypesmodule are not imported, we can useobjectas a general type for now.