From a318ca62e88e982e54ccea904d94673190f11bf1 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 7 Jan 2024 18:23:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=20check=20filled=20=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=B0=20load=20file=20=E5=92=8C=20init=20=E5=90=8E=E9=9D=A2?= =?UTF-8?q?=E6=9D=A5=E5=85=81=E8=AE=B8=E8=87=AA=E5=AE=9A=E4=B9=89=E5=A1=AB?= =?UTF-8?q?=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/lib_not_dr/__init__.py | 2 +- src/lib_not_dr/types/options.py | 23 ++++++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c9409b1..2d2bbba 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A python lib came from [Difficult Rocket](https://github.com/shenjackyuanjie/Dif ## Information/信息 -- Version / 版本: 0.3.14 +- Version / 版本: 0.3.15 - Author / 作者: shenjackyuanjie <3695888@qq.com> [shenjackyuanjie](https://github.com/shenjackyuanjie) diff --git a/src/lib_not_dr/__init__.py b/src/lib_not_dr/__init__.py index 213da3b..a1e2e84 100644 --- a/src/lib_not_dr/__init__.py +++ b/src/lib_not_dr/__init__.py @@ -9,7 +9,7 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: from lib_not_dr import loggers, nuitka, types, command -_version_ = "0.3.14" +_version_ = "0.3.15" # fmt: off __all__ = [ diff --git a/src/lib_not_dr/types/options.py b/src/lib_not_dr/types/options.py index 74d372c..86f735b 100644 --- a/src/lib_not_dr/types/options.py +++ b/src/lib_not_dr/types/options.py @@ -112,10 +112,6 @@ class Options: setattr(self, option, value) if self._check_filled: miss_list.remove(option) - if self._check_filled and miss_list: - raise OptionNotFilled( - f"option: {miss_list} is not filled in {self.name}" - ) run_load_file = True if hasattr(self, "init"): run_load_file = self.init(**kwargs) # 默认 False/None @@ -125,6 +121,10 @@ class Options: self.load_file() except Exception: traceback.print_exc() + if self._check_filled and miss_list: + raise OptionNotFilled( + f"option: {miss_list} is not filled in {self.name}" + ) self.flush_option() def __str__(self): @@ -140,12 +140,12 @@ class Options: if TYPE_CHECKING: _options: Dict[str, Union[Callable, object]] = {} - def init(self, **kwargs) -> bool: + def init(self, **kwargs) -> bool: # type: ignore """如果子类定义了这个函数,则会在 __init__ 之后调用这个函数 返回值为 True 则不会调用 load_file 函数 """ - def load_file(self) -> bool: + def load_file(self) -> bool: # type: ignore """如果子类定义了这个函数,则会在 __init__ 和 init 之后再调用这个函数 请注意,这个函数请尽量使用 try 包裹住可能出现错误的部分 @@ -238,7 +238,7 @@ class Options: max_len_value = max(max_len_value, len(str(value))) max_len_value_t = max(max_len_value_t, len(str(value_t))) option_list.append([key, value, value_t]) - return [option_list, max_len_key, max_len_value, max_len_value_t] # noqa + return [option_list, max_len_key, max_len_value, max_len_value_t] # type: ignore def as_markdown(self, longest: Optional[int] = None) -> str: """ @@ -296,14 +296,15 @@ class Options: # 所以可以直接修改 string for v in value[0]: if len(str(v[0])) > option_len: - v[0] = f"{str(v[0])[:value_len - 3]}..." + v[0] = f"{str(v[0])[:value_len - 3]}..." # type: ignore if len(str(v[1])) > value_len: - v[1] = f"{str(v[1])[:value_len - 3]}..." + v[1] = f"{str(v[1])[:value_len - 3]}..." # type: ignore if len(str(v[2])) > value_type_len: - v[2] = f"{str(v[2])[:value_len - 3]}.." + v[2] = f"{str(v[2])[:value_len - 3]}.." # type: ignore cache.write( - f"| Option{' ' * (option_len - 3)}| Value{' ' * (value_len - 2)}| Value Type{' ' * (value_type_len - 7)}|\n" + f"| Option{' ' * (option_len - 3)}| Value{' ' * (value_len - 2)}" + f"| Value Type{' ' * (value_type_len - 7)}|\n" ) cache.write( f'|:{"-" * (option_len + 3)}|:{"-" * (value_len + 3)}|:{"-" * (value_type_len + 3)}|\n'