From ed67e7482808d1fc40291307e62faf558db9c8a3 Mon Sep 17 00:00:00 2001 From: Nick Mills-Barrett Date: Sat, 9 Mar 2024 11:42:24 +0000 Subject: [PATCH] Fix remaining type issues with arguments dicts --- pyinfra/api/arguments.py | 5 +++-- pyinfra/api/arguments_typed.py | 14 ++++++++++++-- pyinfra/api/host.py | 2 +- pyinfra/api/operation.py | 2 +- pyinfra/api/operations.py | 9 ++++----- tests/words.txt | 3 +++ 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/pyinfra/api/arguments.py b/pyinfra/api/arguments.py index 4887289b2..d5e00e14f 100644 --- a/pyinfra/api/arguments.py +++ b/pyinfra/api/arguments.py @@ -6,6 +6,7 @@ Callable, Generic, Iterable, + List, Mapping, Optional, TypeVar, @@ -169,7 +170,7 @@ class MetaArguments(TypedDict): name: str _ignore_errors: bool _continue_on_error: bool - _if: list[Callable[[], bool]] + _if: List[Callable[[], bool]] meta_argument_meta: dict[str, ArgumentMeta] = { @@ -299,7 +300,7 @@ def pop_global_arguments( if context.ctx_config.isset(): config = context.config - meta_kwargs: dict[str, Any] = cast(dict[str, Any], host.current_deploy_kwargs) or {} + meta_kwargs: dict[str, Any] = host.current_deploy_kwargs or {} # type: ignore[assignment] arguments: dict[str, Any] = {} found_keys: list[str] = [] diff --git a/pyinfra/api/arguments_typed.py b/pyinfra/api/arguments_typed.py index 8430bd543..5b3e441d7 100644 --- a/pyinfra/api/arguments_typed.py +++ b/pyinfra/api/arguments_typed.py @@ -1,6 +1,16 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, Generator, Generic, Iterable, Mapping, Optional, Union +from typing import ( + TYPE_CHECKING, + Callable, + Generator, + Generic, + Iterable, + List, + Mapping, + Optional, + Union, +) from typing_extensions import ParamSpec, Protocol @@ -51,7 +61,7 @@ def __call__( name: Optional[str] = None, _ignore_errors: bool = False, _continue_on_error: bool = False, - _if: Optional[list[Callable[[], bool]]] = None, + _if: Optional[List[Callable[[], bool]]] = None, # # ExecutionArguments # diff --git a/pyinfra/api/host.py b/pyinfra/api/host.py index 564534dbc..b8503c12d 100644 --- a/pyinfra/api/host.py +++ b/pyinfra/api/host.py @@ -10,13 +10,13 @@ Type, TypeVar, Union, - Unpack, cast, overload, ) from uuid import uuid4 import click +from typing_extensions import Unpack from pyinfra import logger from pyinfra.connectors.base import BaseConnector diff --git a/pyinfra/api/operation.py b/pyinfra/api/operation.py index 57f100310..0b53d51fc 100644 --- a/pyinfra/api/operation.py +++ b/pyinfra/api/operation.py @@ -214,7 +214,7 @@ def decorated_func(*args: P.args, **kwargs: P.kwargs) -> OperationMeta: if func.deprecated_for: # type: ignore[attr-defined] logger.warning( f"The {get_operation_name_from_func(func)} operation is " - + f"deprecated, please use: {func.deprecated_for}", # type: ignore[attr-defined] + + f"deprecated, please use: {func.deprecated_for}", # type: ignore[attr-defined] # noqa ) else: logger.warning(f"The {get_operation_name_from_func(func)} operation is deprecated") diff --git a/pyinfra/api/operations.py b/pyinfra/api/operations.py index e121d49a9..1e38eedb4 100644 --- a/pyinfra/api/operations.py +++ b/pyinfra/api/operations.py @@ -67,11 +67,10 @@ def _run_host_op(state: "State", host: "Host", op_hash: str) -> Optional[bool]: timeout = global_arguments.get("_timeout", 0) executor_kwarg_keys = CONNECTOR_ARGUMENT_KEYS - base_connector_arguments: ConnectorArguments = ( - cast( # https://github.com/python/mypy/issues/10371 - ConnectorArguments, - {key: global_arguments[key] for key in executor_kwarg_keys if key in global_arguments}, - ) + # See: https://github.com/python/mypy/issues/10371 + base_connector_arguments: ConnectorArguments = cast( + ConnectorArguments, + {key: global_arguments[key] for key in executor_kwarg_keys if key in global_arguments}, # type: ignore[literal-required] # noqa ) did_error = False diff --git a/tests/words.txt b/tests/words.txt index 8dd8a9b8c..25a0d9faf 100644 --- a/tests/words.txt +++ b/tests/words.txt @@ -127,6 +127,7 @@ e501 ed25519 endian entrypoint +envvar epel excuted exe @@ -343,6 +344,7 @@ status stdlib stringify stringio +strs su subclassed subclassing @@ -383,6 +385,7 @@ ufw uname unignored unmount +unresposivehost up up2 useradd