diff --git a/python/online/fxreader/pr34/commands_typed/cli_bootstrap.py b/python/online/fxreader/pr34/commands_typed/cli_bootstrap.py index 44304ef..0fd3b20 100644 --- a/python/online/fxreader/pr34/commands_typed/cli_bootstrap.py +++ b/python/online/fxreader/pr34/commands_typed/cli_bootstrap.py @@ -101,6 +101,43 @@ def check_dict( value, ) +@overload +def check_list( + value: Any, + VT: Type[Value], +) -> list[Value]: ... + +@overload +def check_list( + value: Any, +) -> list[Any]: ... + +def check_list( + value: Any, + VT: Optional[Type[Value]] = None, +) -> list[Value] | list[Any]: + assert isinstance(value, list) + value2 = cast(list[Any], value) + + assert all([ + ( + VT is None or + isinstance(o, VT) + ) + for o in value2 + ]) + + if VT is None: + return cast( + list[Any], + value, + ) + else: + return cast( + list[Value], + value, + ) + def pyproject_load( d: pathlib.Path, ) -> PyProject: @@ -148,18 +185,11 @@ def pyproject_load( tool_name = 'online.fxreader.pr34'.replace('.', '-') if ( - 'tool' in content and - isinstance( - content['tool'], dict - ) and - all([ - isinstance(o, str) - for o in content['tool'] - ]) + 'tool' in content ): - res.tool = cast( - dict[str, Any], - content['tool'] + res.tool = check_dict( + content['tool'], + str, ) if ( @@ -173,42 +203,52 @@ def pyproject_load( dict ) ): - if 'early_features' in content['tool'][tool_name]: - res.early_features = content['tool'][tool_name]['early_features'] + pr34_tool = check_dict( + check_dict( + content['tool'], + str, + )[tool_name], + str + ) - if 'pip_find_links' in content['tool'][tool_name]: + if 'early_features' in pr34_tool: + res.early_features = pr34_tool['early_features'] + + if 'pip_find_links' in pr34_tool: res.pip_find_links = [ d.parent / pathlib.Path(o) - for o in content['tool'][tool_name]['pip_find_links'] + for o in pr34_tool['pip_find_links'] ] - if 'runtime_libdirs' in content['tool'][tool_name]: + if 'runtime_libdirs' in pr34_tool: res.runtime_libdirs = [ d.parent / pathlib.Path(o) # pathlib.Path(o) - for o in content['tool'][tool_name]['runtime_libdirs'] + for o in pr34_tool['runtime_libdirs'] ] - if 'runtime_preload' in content['tool'][tool_name]: + if 'runtime_preload' in pr34_tool: res.runtime_preload = [ d.parent / pathlib.Path(o) # pathlib.Path(o) - for o in content['tool'][tool_name]['runtime_preload'] + for o in pr34_tool['runtime_preload'] ] - if 'requirements' in content['tool'][tool_name]: - assert isinstance(content['tool'][tool_name]['requirements'], dict) - + if 'requirements' in pr34_tool: res.requirements = { k : d.parent / pathlib.Path(v) # pathlib.Path(o) - for k, v in content['tool'][tool_name]['requirements'].items() + for k, v in check_dict( + pr34_tool['requirements'], + str, + str + ).items() } - if 'modules' in content['tool'][tool_name]: - modules = content['tool'][tool_name]['modules'] - assert isinstance(modules, list) - + if 'modules' in pr34_tool: + modules = check_list( + pr34_tool['modules'] + ) # res.modules = [] for o in modules: