diff --git a/geth/accounts.py b/geth/accounts.py index 3df889e..38047bd 100644 --- a/geth/accounts.py +++ b/geth/accounts.py @@ -29,7 +29,7 @@ def get_accounts(data_dir: str, **geth_kwargs: Any) -> tuple[str, ...] | tuple[( """ validate_geth_kwargs(geth_kwargs) - command, proc = spawn_geth( # type: ignore[no-untyped-call] + command, proc = spawn_geth( dict(data_dir=data_dir, suffix_args=["account", "list"], **geth_kwargs) ) stdoutdata, stderrdata = proc.communicate() @@ -122,7 +122,7 @@ def target_account() -> str: elif not isinstance(password, bytes): raise ValueError("Password must be either a path to a file or bytes") - command, proc = spawn_geth(geth_kwargs) # type: ignore[no-untyped-call] + command, proc = spawn_geth(geth_kwargs) if isinstance(password, str): stdoutdata, stderrdata = proc.communicate() diff --git a/geth/main.py b/geth/main.py index f65a389..e5ddaaa 100644 --- a/geth/main.py +++ b/geth/main.py @@ -2,6 +2,10 @@ import semantic_version +from geth.utils.validation import ( + validate_geth_kwargs, +) + from .utils.encoding import ( force_text, ) @@ -17,6 +21,7 @@ def get_geth_version_info_string(**geth_kwargs): "`suffix_args` parameter" ) geth_kwargs["suffix_args"] = ["version"] + validate_geth_kwargs(geth_kwargs) stdoutdata, stderrdata, command, proc = geth_wrapper(**geth_kwargs) return stdoutdata @@ -25,6 +30,7 @@ def get_geth_version_info_string(**geth_kwargs): def get_geth_version(**geth_kwargs): + validate_geth_kwargs(geth_kwargs) version_info_string = get_geth_version_info_string(**geth_kwargs) version_match = re.search(VERSION_REGEX, force_text(version_info_string, "utf8")) if not version_match: diff --git a/geth/process.py b/geth/process.py index 6663bbd..e5b5feb 100644 --- a/geth/process.py +++ b/geth/process.py @@ -71,6 +71,7 @@ def __init__( stdout=subprocess.PIPE, stderr=subprocess.PIPE, ): + validate_geth_kwargs(geth_kwargs) self.geth_kwargs = geth_kwargs self.command = construct_popen_command(**geth_kwargs) self.stdin = stdin diff --git a/geth/reset.py b/geth/reset.py index f69d9c4..69daa5d 100644 --- a/geth/reset.py +++ b/geth/reset.py @@ -25,9 +25,7 @@ def soft_reset_chain( - allow_live: bool = False, - allow_testnet: bool = False, - **geth_kwargs: Any, + allow_live: bool = False, allow_testnet: bool = False, **geth_kwargs: Any ) -> None: validate_geth_kwargs(geth_kwargs) data_dir = geth_kwargs.get("data_dir") @@ -46,7 +44,7 @@ def soft_reset_chain( suffix_args.extend(("removedb",)) geth_kwargs.update({"suffix_args": suffix_args}) - _, proc = spawn_geth(geth_kwargs) # type: ignore[no-untyped-call] + _, proc = spawn_geth(geth_kwargs) stdoutdata, stderrdata = proc.communicate(b"y") diff --git a/geth/wrapper.py b/geth/wrapper.py index 2f16226..0655346 100644 --- a/geth/wrapper.py +++ b/geth/wrapper.py @@ -26,6 +26,9 @@ get_open_port, is_port_open, ) +from geth.utils.validation import ( + validate_geth_kwargs, +) is_nice_available = functools.partial(is_executable_available, "nice") @@ -305,8 +308,8 @@ def construct_popen_command( # type: ignore return builder.command -# type ignored TODO rethink GethKwargs in a separate PR def geth_wrapper(**geth_kwargs): # type: ignore[no-untyped-def] + validate_geth_kwargs(geth_kwargs) stdin = geth_kwargs.pop("stdin", None) command = construct_popen_command(**geth_kwargs) # type: ignore[no-untyped-call] @@ -334,10 +337,13 @@ def geth_wrapper(**geth_kwargs): # type: ignore[no-untyped-def] return stdoutdata, stderrdata, command, proc -# type ignored TODO rethink GethKwargs in a separate PR def spawn_geth( # type: ignore[no-untyped-def] - geth_kwargs, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE + geth_kwargs: dict[str, Any], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, ): + validate_geth_kwargs(geth_kwargs) command = construct_popen_command(**geth_kwargs) # type: ignore[no-untyped-call] proc = subprocess.Popen(