Skip to content

Commit

Permalink
chore: auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 2, 2024
1 parent d23a27a commit 79afabd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/ansiblelint/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def content(self) -> str:
"""Retrieve file content, from internal cache or disk."""
if self._content is None:
self._populate_content_cache_from_disk()
return cast(str, self._content)
return cast("str", self._content)

@content.setter
def content(self, value: str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ def transform(self, match, lintable, data):
# The cast() calls tell mypy what types we expect.
# Essentially this does:
if isinstance(segment, str):
target = cast(MutableMapping[str, Any], target)[segment]
target = cast("MutableMapping[str, Any]", target)[segment]
elif isinstance(segment, int):
target = cast(MutableSequence[Any], target)[segment]
target = cast("MutableSequence[Any]", target)[segment]
return target


Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ def _do_transforms(
_logger.debug("%s %s", self.FIX_NA_MSG, match_id)
continue
if self.write_set != {"all"}:
rule = cast(AnsibleLintRule, match.rule)
rule = cast("AnsibleLintRule", match.rule)
rule_definition = set(rule.tags)
rule_definition.add(rule.id)
if rule_definition.isdisjoint(self.write_set):
_logger.debug("%s %s", self.FIX_NE_MSG, match_id)
continue
if file_is_yaml and not match.yaml_path:
data = cast(CommentedMap | CommentedSeq, data)
data = cast("CommentedMap | CommentedSeq", data)
if match.match_type == "play":
match.yaml_path = get_path_to_play(file, match.lineno, data)
elif match.task or file.kind in (
Expand Down
20 changes: 10 additions & 10 deletions src/ansiblelint/yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ def _nested_items_path(
# convert_to_tuples_type = Callable[[], Iterator[tuple[str | int, Any]]]
if isinstance(data_collection, dict):
convert_data_collection_to_tuples = cast(
Callable[[], Iterator[tuple[str | int, Any]]],
"Callable[[], Iterator[tuple[str | int, Any]]]",
functools.partial(data_collection.items),
)
elif isinstance(data_collection, list):
convert_data_collection_to_tuples = cast(
Callable[[], Iterator[tuple[str | int, Any]]],
"Callable[[], Iterator[tuple[str | int, Any]]]",
functools.partial(enumerate, data_collection),
)
else:
Expand Down Expand Up @@ -914,11 +914,11 @@ def __init__( # pylint: disable=too-many-arguments
self.explicit_start: bool = config["explicit_start"] # type: ignore[assignment]
self.explicit_end: bool = config["explicit_end"] # type: ignore[assignment]
self.width: int = config["width"] # type: ignore[assignment]
indent_sequences: bool = cast(bool, config["indent_sequences"])
preferred_quote: str = cast(str, config["preferred_quote"]) # either ' or "
indent_sequences: bool = cast("bool", config["indent_sequences"])
preferred_quote: str = cast("str", config["preferred_quote"]) # either ' or "

min_spaces_inside: int = cast(int, config["min_spaces_inside"])
max_spaces_inside: int = cast(int, config["max_spaces_inside"])
min_spaces_inside: int = cast("int", config["min_spaces_inside"])
max_spaces_inside: int = cast("int", config["max_spaces_inside"])

self.default_flow_style = False
self.compact_seq_seq = True # type: ignore[assignment] # dash after dash
Expand Down Expand Up @@ -996,7 +996,7 @@ def _defaults_from_yamllint_config() -> dict[str, bool | int | str]:
elif quote_type == "double":
config["preferred_quote"] = '"'

return cast(dict[str, bool | int | str], config)
return cast("dict[str, bool | int | str]", config)

@property
def version(self) -> tuple[int, int] | None:
Expand Down Expand Up @@ -1095,17 +1095,17 @@ def _predict_indent_length(self, parent_path: list[str | int], key: Any) -> int:
indent += self.sequence_dash_offset
elif isinstance(parent_key, int):
# next level is a sequence
indent += cast(int, self.sequence_indent)
indent += cast("int", self.sequence_indent)

Check warning on line 1098 in src/ansiblelint/yaml_utils.py

View check run for this annotation

Codecov / codecov/patch

src/ansiblelint/yaml_utils.py#L1098

Added line #L1098 was not covered by tests
elif isinstance(parent_key, str):
# next level is a map
indent += cast(int, self.map_indent)
indent += cast("int", self.map_indent)

if isinstance(key, int) and indent == 0:
# flow map is an item in a root-level sequence
indent += self.sequence_dash_offset
elif isinstance(key, int) and indent > 0:
# flow map is in a sequence
indent += cast(int, self.sequence_indent)
indent += cast("int", self.sequence_indent)
elif isinstance(key, str):
# flow map is in a map
indent += len(key + ": ")
Expand Down
2 changes: 1 addition & 1 deletion test/test_yaml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ def test_document_start(

yaml = ansiblelint.yaml_utils.FormattedYAML(
version=yaml_version,
config=cast(dict[str, bool | int | str], config),
config=cast("dict[str, bool | int | str]", config),
)
assert (
yaml.dumps(yaml.load(_SINGLE_QUOTE_WITHOUT_INDENTS)).startswith("---")
Expand Down

0 comments on commit 79afabd

Please sign in to comment.