Skip to content

Commit

Permalink
Remove unnecessary casts
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Dec 2, 2024
1 parent 38ba88c commit 3393d89
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/molecule/dependency/ansible_galaxy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def options(self) -> MutableMapping[str, str | bool]:
Returns:
Merged and filtered options for this dependency.
"""
opts: MutableMapping[str, str | bool] = self._config.config["dependency"]["options"]
opts = self._config.config["dependency"]["options"]
# NOTE(retr0h): Remove verbose options added by the user while in
# debug.
if self._config.debug:
Expand Down
4 changes: 2 additions & 2 deletions src/molecule/dependency/ansible_galaxy/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging

from pathlib import Path
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, cast

from molecule import util
from molecule.dependency.ansible_galaxy.base import AnsibleGalaxyBase
Expand Down Expand Up @@ -58,4 +58,4 @@ def requirements_file(self) -> str:
Returns:
Path to the requirements file for this dependency.
"""
return self.options["requirements-file"] # type: ignore[return-value]
return cast(str, self.options["requirements-file"])
4 changes: 2 additions & 2 deletions src/molecule/dependency/ansible_galaxy/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging

from pathlib import Path
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, cast

from molecule import util
from molecule.dependency.ansible_galaxy.base import AnsibleGalaxyBase
Expand Down Expand Up @@ -57,4 +57,4 @@ def requirements_file(self) -> str:
Returns:
Path to the requirements file for this dependency.
"""
return self.options["role-file"] # type: ignore[return-value]
return cast(str, self.options["role-file"])
11 changes: 6 additions & 5 deletions src/molecule/provisioner/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@


if TYPE_CHECKING:
from collections.abc import MutableMapping
from typing import Any

from molecule.types import Options

Vivify = collections.defaultdict[str, Any | "Vivify"]


Expand Down Expand Up @@ -578,17 +579,17 @@ def config_options(self) -> dict[str, Any]:
)

@property
def options(self) -> MutableMapping[str, str | bool]: # noqa: D102
def options(self) -> Options: # noqa: D102
if self._config.action in ["create", "destroy"]:
return self.default_options

o: MutableMapping[str, str | bool] = self._config.config["provisioner"]["options"]
opts = self._config.config["provisioner"]["options"]
# NOTE(retr0h): Remove verbose options added by the user while in
# debug.
if self._config.debug:
o = util.filter_verbose_permutation(o)
opts = util.filter_verbose_permutation(opts)

return util.merge_dicts(self.default_options, o)
return util.merge_dicts(self.default_options, opts)

@property
def env(self) -> dict[str, str]: # noqa: D102
Expand Down
5 changes: 2 additions & 3 deletions src/molecule/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

from __future__ import annotations

from collections.abc import MutableMapping
from typing import TYPE_CHECKING, TypedDict


if TYPE_CHECKING:
from collections.abc import MutableMapping
from typing import Any, Literal, TypeAlias


Options: TypeAlias = MutableMapping[str, str | bool]
Options: TypeAlias = MutableMapping[str, str | bool]


class DependencyData(TypedDict, total=False):
Expand Down
10 changes: 4 additions & 6 deletions src/molecule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@


if TYPE_CHECKING:
from collections.abc import Generator, Iterable, Mapping, MutableMapping
from collections.abc import Generator, Iterable, MutableMapping
from io import TextIOWrapper
from typing import Any, AnyStr, NoReturn, TypeVar
from warnings import WarningMessage

from molecule.types import CommandArgs, ConfigData, PlatformData
from molecule.types import CommandArgs, ConfigData, Options, PlatformData

NestedDict = MutableMapping[str, Any]
_T = TypeVar("_T", bound=NestedDict)
Expand Down Expand Up @@ -355,7 +355,7 @@ def instance_with_scenario_name(instance_name: str, scenario_name: str) -> str:
return f"{instance_name}-{scenario_name}"


def verbose_flag(options: MutableMapping[str, str | bool]) -> list[str]:
def verbose_flag(options: Options) -> list[str]:
"""Return computed verbosity flag.
Args:
Expand All @@ -378,9 +378,7 @@ def verbose_flag(options: MutableMapping[str, str | bool]) -> list[str]:
return flags


def filter_verbose_permutation(
options: Mapping[str, str | bool],
) -> MutableMapping[str, str | bool]:
def filter_verbose_permutation(options: Options) -> Options:
"""Clean verbose information.
Args:
Expand Down

0 comments on commit 3393d89

Please sign in to comment.