Skip to content

Commit a5fbd7c

Browse files
authored
Update ruff to 0.8.1 (#4440)
1 parent 7636407 commit a5fbd7c

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ repos:
134134
hooks:
135135
- id: toml-sort-fix
136136
- repo: https://github.com/astral-sh/ruff-pre-commit
137-
rev: v0.8.0
137+
rev: v0.8.1
138138
hooks:
139139
- id: ruff
140140
args:

src/ansiblelint/file_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def content(self) -> str:
326326
"""Retrieve file content, from internal cache or disk."""
327327
if self._content is None:
328328
self._populate_content_cache_from_disk()
329-
return cast(str, self._content)
329+
return cast("str", self._content)
330330

331331
@content.setter
332332
def content(self, value: str) -> None:

src/ansiblelint/rules/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ def transform(self, match, lintable, data):
327327
# The cast() calls tell mypy what types we expect.
328328
# Essentially this does:
329329
if isinstance(segment, str):
330-
target = cast(MutableMapping[str, Any], target)[segment]
330+
target = cast("MutableMapping[str, Any]", target)[segment]
331331
elif isinstance(segment, int):
332-
target = cast(MutableSequence[Any], target)[segment]
332+
target = cast("MutableSequence[Any]", target)[segment]
333333
return target
334334

335335

src/ansiblelint/transformer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
from ruamel.yaml.comments import CommentedMap, CommentedSeq
1010

1111
from ansiblelint.file_utils import Lintable
12-
from ansiblelint.rules import AnsibleLintRule, TransformMixin
12+
from ansiblelint.rules import TransformMixin
1313
from ansiblelint.yaml_utils import FormattedYAML, get_path_to_play, get_path_to_task
1414

1515
if TYPE_CHECKING:
1616
from ansiblelint.config import Options
1717
from ansiblelint.errors import MatchError
18+
from ansiblelint.rules import AnsibleLintRule
1819
from ansiblelint.runner import LintResult
1920

2021
__all__ = ["Transformer"]
@@ -150,14 +151,14 @@ def _do_transforms(
150151
_logger.debug("%s %s", self.FIX_NA_MSG, match_id)
151152
continue
152153
if self.write_set != {"all"}:
153-
rule = cast(AnsibleLintRule, match.rule)
154+
rule = cast("AnsibleLintRule", match.rule)
154155
rule_definition = set(rule.tags)
155156
rule_definition.add(rule.id)
156157
if rule_definition.isdisjoint(self.write_set):
157158
_logger.debug("%s %s", self.FIX_NE_MSG, match_id)
158159
continue
159160
if file_is_yaml and not match.yaml_path:
160-
data = cast(CommentedMap | CommentedSeq, data)
161+
data = cast("CommentedMap | CommentedSeq", data)
161162
if match.match_type == "play":
162163
match.yaml_path = get_path_to_play(file, match.lineno, data)
163164
elif match.task or file.kind in (

src/ansiblelint/yaml_utils.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import logging
88
import os
99
import re
10-
from collections.abc import Callable, Iterator, Sequence
1110
from io import StringIO
1211
from pathlib import Path
1312
from re import Pattern
@@ -35,6 +34,8 @@
3534

3635
if TYPE_CHECKING:
3736
# noinspection PyProtectedMember
37+
from collections.abc import Callable, Iterator, Sequence
38+
3839
from ruamel.yaml.comments import LineCol
3940
from ruamel.yaml.nodes import ScalarNode
4041
from ruamel.yaml.representer import RoundTripRepresenter
@@ -247,12 +248,12 @@ def _nested_items_path(
247248
# convert_to_tuples_type = Callable[[], Iterator[tuple[str | int, Any]]]
248249
if isinstance(data_collection, dict):
249250
convert_data_collection_to_tuples = cast(
250-
Callable[[], Iterator[tuple[str | int, Any]]],
251+
"Callable[[], Iterator[tuple[str | int, Any]]]",
251252
functools.partial(data_collection.items),
252253
)
253254
elif isinstance(data_collection, list):
254255
convert_data_collection_to_tuples = cast(
255-
Callable[[], Iterator[tuple[str | int, Any]]],
256+
"Callable[[], Iterator[tuple[str | int, Any]]]",
256257
functools.partial(enumerate, data_collection),
257258
)
258259
else:
@@ -914,11 +915,11 @@ def __init__( # pylint: disable=too-many-arguments
914915
self.explicit_start: bool = config["explicit_start"] # type: ignore[assignment]
915916
self.explicit_end: bool = config["explicit_end"] # type: ignore[assignment]
916917
self.width: int = config["width"] # type: ignore[assignment]
917-
indent_sequences: bool = cast(bool, config["indent_sequences"])
918-
preferred_quote: str = cast(str, config["preferred_quote"]) # either ' or "
918+
indent_sequences: bool = cast("bool", config["indent_sequences"])
919+
preferred_quote: str = cast("str", config["preferred_quote"]) # either ' or "
919920

920-
min_spaces_inside: int = cast(int, config["min_spaces_inside"])
921-
max_spaces_inside: int = cast(int, config["max_spaces_inside"])
921+
min_spaces_inside: int = cast("int", config["min_spaces_inside"])
922+
max_spaces_inside: int = cast("int", config["max_spaces_inside"])
922923

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

999-
return cast(dict[str, bool | int | str], config)
1000+
return cast("dict[str, bool | int | str]", config)
10001001

10011002
@property
10021003
def version(self) -> tuple[int, int] | None:
@@ -1095,17 +1096,17 @@ def _predict_indent_length(self, parent_path: list[str | int], key: Any) -> int:
10951096
indent += self.sequence_dash_offset
10961097
elif isinstance(parent_key, int):
10971098
# next level is a sequence
1098-
indent += cast(int, self.sequence_indent)
1099+
indent += cast("int", self.sequence_indent)
10991100
elif isinstance(parent_key, str):
11001101
# next level is a map
1101-
indent += cast(int, self.map_indent)
1102+
indent += cast("int", self.map_indent)
11021103

11031104
if isinstance(key, int) and indent == 0:
11041105
# flow map is an item in a root-level sequence
11051106
indent += self.sequence_dash_offset
11061107
elif isinstance(key, int) and indent > 0:
11071108
# flow map is in a sequence
1108-
indent += cast(int, self.sequence_indent)
1109+
indent += cast("int", self.sequence_indent)
11091110
elif isinstance(key, str):
11101111
# flow map is in a map
11111112
indent += len(key + ": ")

test/test_yaml_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ def test_document_start(
10291029

10301030
yaml = ansiblelint.yaml_utils.FormattedYAML(
10311031
version=yaml_version,
1032-
config=cast(dict[str, bool | int | str], config),
1032+
config=cast("dict[str, bool | int | str]", config),
10331033
)
10341034
assert (
10351035
yaml.dumps(yaml.load(_SINGLE_QUOTE_WITHOUT_INDENTS)).startswith("---")

0 commit comments

Comments
 (0)