|
7 | 7 | import logging |
8 | 8 | import os |
9 | 9 | import re |
10 | | -from collections.abc import Callable, Iterator, Sequence |
11 | 10 | from io import StringIO |
12 | 11 | from pathlib import Path |
13 | 12 | from re import Pattern |
|
35 | 34 |
|
36 | 35 | if TYPE_CHECKING: |
37 | 36 | # noinspection PyProtectedMember |
| 37 | + from collections.abc import Callable, Iterator, Sequence |
| 38 | + |
38 | 39 | from ruamel.yaml.comments import LineCol |
39 | 40 | from ruamel.yaml.nodes import ScalarNode |
40 | 41 | from ruamel.yaml.representer import RoundTripRepresenter |
@@ -247,12 +248,12 @@ def _nested_items_path( |
247 | 248 | # convert_to_tuples_type = Callable[[], Iterator[tuple[str | int, Any]]] |
248 | 249 | if isinstance(data_collection, dict): |
249 | 250 | convert_data_collection_to_tuples = cast( |
250 | | - Callable[[], Iterator[tuple[str | int, Any]]], |
| 251 | + "Callable[[], Iterator[tuple[str | int, Any]]]", |
251 | 252 | functools.partial(data_collection.items), |
252 | 253 | ) |
253 | 254 | elif isinstance(data_collection, list): |
254 | 255 | convert_data_collection_to_tuples = cast( |
255 | | - Callable[[], Iterator[tuple[str | int, Any]]], |
| 256 | + "Callable[[], Iterator[tuple[str | int, Any]]]", |
256 | 257 | functools.partial(enumerate, data_collection), |
257 | 258 | ) |
258 | 259 | else: |
@@ -914,11 +915,11 @@ def __init__( # pylint: disable=too-many-arguments |
914 | 915 | self.explicit_start: bool = config["explicit_start"] # type: ignore[assignment] |
915 | 916 | self.explicit_end: bool = config["explicit_end"] # type: ignore[assignment] |
916 | 917 | 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 " |
919 | 920 |
|
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"]) |
922 | 923 |
|
923 | 924 | self.default_flow_style = False |
924 | 925 | 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]: |
996 | 997 | elif quote_type == "double": |
997 | 998 | config["preferred_quote"] = '"' |
998 | 999 |
|
999 | | - return cast(dict[str, bool | int | str], config) |
| 1000 | + return cast("dict[str, bool | int | str]", config) |
1000 | 1001 |
|
1001 | 1002 | @property |
1002 | 1003 | def version(self) -> tuple[int, int] | None: |
@@ -1095,17 +1096,17 @@ def _predict_indent_length(self, parent_path: list[str | int], key: Any) -> int: |
1095 | 1096 | indent += self.sequence_dash_offset |
1096 | 1097 | elif isinstance(parent_key, int): |
1097 | 1098 | # next level is a sequence |
1098 | | - indent += cast(int, self.sequence_indent) |
| 1099 | + indent += cast("int", self.sequence_indent) |
1099 | 1100 | elif isinstance(parent_key, str): |
1100 | 1101 | # next level is a map |
1101 | | - indent += cast(int, self.map_indent) |
| 1102 | + indent += cast("int", self.map_indent) |
1102 | 1103 |
|
1103 | 1104 | if isinstance(key, int) and indent == 0: |
1104 | 1105 | # flow map is an item in a root-level sequence |
1105 | 1106 | indent += self.sequence_dash_offset |
1106 | 1107 | elif isinstance(key, int) and indent > 0: |
1107 | 1108 | # flow map is in a sequence |
1108 | | - indent += cast(int, self.sequence_indent) |
| 1109 | + indent += cast("int", self.sequence_indent) |
1109 | 1110 | elif isinstance(key, str): |
1110 | 1111 | # flow map is in a map |
1111 | 1112 | indent += len(key + ": ") |
|
0 commit comments