diff options
| author | 2023-12-08 01:03:07 +0800 | |
|---|---|---|
| committer | 2023-12-08 01:03:07 +0800 | |
| commit | e777e9261caf84be00a218b60045a14741beee7b (patch) | |
| tree | 2b0ee095438f929a27fd0af42e40554c6e1ce45d /src/hydrorollcore/core.py | |
| parent | c10c8237470b5edb6a383e557324fab06fc8d855 (diff) | |
| parent | d3076462c53afc848622052611a2ed7c241434e9 (diff) | |
| download | infini-e777e9261caf84be00a218b60045a14741beee7b.tar.gz infini-e777e9261caf84be00a218b60045a14741beee7b.zip | |
Merge pull request #32 from fu050409/master
🎨 优化抽象基类
Diffstat (limited to 'src/hydrorollcore/core.py')
| -rw-r--r-- | src/hydrorollcore/core.py | 13 |
1 files changed, 8 insertions, 5 deletions
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}" |
