From c888c7e2da25137839c1a9af911df2f4eb3990d7 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Thu, 11 May 2023 00:31:13 +0800 Subject: [PATCH] options -> _options --- Difficult_Rocket/utils/options.py | 18 +++++++++--------- docs/src/update_logs.md | 4 +++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Difficult_Rocket/utils/options.py b/Difficult_Rocket/utils/options.py index 530a9d6..06a6ec4 100644 --- a/Difficult_Rocket/utils/options.py +++ b/Difficult_Rocket/utils/options.py @@ -51,7 +51,7 @@ class Options: :param kwargs: """ if TYPE_CHECKING: - self.options: Dict[str, Union[Callable, object]] = {} + self._options: Dict[str, Union[Callable, object]] = {} self.flush_option() for option, value in kwargs.items(): if option not in self.cached_options: @@ -67,7 +67,7 @@ class Options: self.flush_option() if TYPE_CHECKING: - options: Dict[str, Union[Callable, object]] = {} + _options: Dict[str, Union[Callable, object]] = {} def init(self, **kwargs) -> None: """ 如果子类定义了这个函数,则会在 __init__ 之后调用这个函数 """ @@ -90,9 +90,9 @@ class Options: if values[ann] is None: values[ann] = self.__annotations__[ann] - if not hasattr(self, 'options'): - self.options: Dict[str, Union[Callable, object]] = {} - for option, a_fun in self.options.items(): # 获取额外内容 + if not hasattr(self, '_options'): + self._options: Dict[str, Union[Callable, object]] = {} + for option, a_fun in self._options.items(): # 获取额外内容 values[option] = a_fun for option, a_fun in values.items(): # 检查是否为 property @@ -156,10 +156,10 @@ class Options: @classmethod def add_option(cls, name: str, value: Union[Callable, object]) -> Dict: - if not hasattr(cls, 'options'): - cls.options: Dict[str, Union[Callable, object]] = {} - cls.options[name] = value - return cls.options + if not hasattr(cls, '_options'): + cls._options: Dict[str, Union[Callable, object]] = {} + cls._options[name] = value + return cls._options @staticmethod def init_option(options_class: Type['Options'], init_value: Optional[dict] = None) -> 'Options': diff --git a/docs/src/update_logs.md b/docs/src/update_logs.md index 549172d..1c5a2ce 100644 --- a/docs/src/update_logs.md +++ b/docs/src/update_logs.md @@ -104,10 +104,12 @@ - `Difficult_Rocket.api` - 大重构,移除定义,改为引用 - Big refactoring, remove definition, change to reference +- `Difficult_Rocket.api.types.Options` ( `Difficult_Rocket.utils.options.Options` ) + - `options` -> `_options` ### Add -- `Difficult_Rocket.api.types.Options` +- `Difficult_Rocket.api.types.Options` ( `Difficult_Rocket.utils.options.Options` ) - 添加 `as_markdown` 方法 - 用于方便的用人类可读的 Markdown 格式 直接输出一个已经实例化的 `Options` 类的所有字段 - Add `as_markdown` method