From a5f3f08f9ae4465b723ed827c72dada74fdb473c Mon Sep 17 00:00:00 2001 From: 苏向夜 Date: Tue, 5 Dec 2023 15:05:17 +0800 Subject: :rocket: 优化抽象基类 修复部分声明异常 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hydrorollcore/core.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/hydrorollcore/core.py') diff --git a/src/hydrorollcore/core.py b/src/hydrorollcore/core.py index 56ec9404..6f6bbcc1 100644 --- a/src/hydrorollcore/core.py +++ b/src/hydrorollcore/core.py @@ -2,24 +2,27 @@ import importlib from typing import List from .exceptions import RuleLoadError from .rule import Rule +from .config import Config class Core: - def __init__(self, config): + def __init__(self, config: Config): self.rule_dir = config.rule_dir self.rules = config.rules - async def load_rules(self) -> List[Rule]: + def load_rules(self) -> List[Rule]: loaded_rules = [] for rule in self.rules: try: module = importlib.import_module(rule) except ImportError as e: - raise RuleLoadError(f'Failed to load rule {rule}: {e}') from e + raise RuleLoadError(f"Failed to load rule {rule}: {e}") from e try: - rule_cls = getattr(module, rule.split('.')[-1]) + rule_cls = getattr(module, rule.split(".")[-1]) if not issubclass(rule_cls, Rule): - raise RuleLoadError(f"Class '{rule_cls.__name__}' is not a subclass of 'Rule'") + raise RuleLoadError( + f"Class '{rule_cls.__name__}' is not a subclass of 'Rule'" + ) except AttributeError as e: raise RuleLoadError( f"Failed to get rule class from module '{rule}': {e}" -- cgit v1.2.3-70-g09d2