Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More types (2) #1704

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ansible_navigator/actions/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def _collect_image_list(self) -> None:

try:
legacy_check = details["config"]["working_dir"] == "/runner"
except KeyError:
except (KeyError, TypeError):
legacy_check = False

# podman has a root label
Expand Down
14 changes: 9 additions & 5 deletions src/ansible_navigator/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def console_width() -> int:


# TODO: Replace this with something type-safe.
def dispatch(obj, replacements):
def dispatch(obj: object, replacements: tuple[tuple[str, str], ...]) -> object:
"""Make the replacement based on type.

:param obj: An obj in which replacements will be made
Expand All @@ -154,7 +154,10 @@ def escape_moustaches(obj: Mapping[Any, Any]) -> Mapping[Any, Any]:
:returns: The obj with replacements made
"""
replacements = (("{", "U+007B"), ("}", "U+007D"))
return dispatch(obj, replacements)
result = dispatch(obj, replacements)
if not isinstance(result, dict):
raise RuntimeError
return result


def environment_variable_is_file_path(
Expand Down Expand Up @@ -321,7 +324,7 @@ def now_iso(time_zone: str) -> str:
PASCAL_REGEX = re.compile("((?<=[a-z0-9])[A-Z]|(?!^)[A-Z](?=[a-z]))")


def pascal_to_snake(obj) -> list[Any] | dict[Any, Any]:
def pascal_to_snake(obj: object) -> object:
"""Convert a pascal cased object into a snake cased object recursively.

:param obj: Pascal cased object
Expand Down Expand Up @@ -522,11 +525,12 @@ def to_list(thing: str | list[Any] | tuple[Any] | set[Any] | None) -> list[Any]:
return converted_value


def unescape_moustaches(obj: Any) -> Mapping[Any, Any]:
def unescape_moustaches(obj: Any) -> Any:
"""Unescape moustaches.

:param obj: Variable that needs to contain moustaches
:returns: The obj with replacements made
"""
replacements = (("U+007B", "{"), ("U+007D", "}"))
return dispatch(obj, replacements)
result = dispatch(obj, replacements)
return result
Loading