diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-06-19 07:03:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2022-06-19 07:03:44 +0000 |
commit | 9262e31316a16180044e0e28a2740238f8aef5c4 (patch) | |
tree | 49b2bc070018965707ec237623da9932c880fae4 /pre_commit_hooks/sort_simple_yaml.py | |
parent | Adding debian version 4.1.0-1. (diff) | |
download | pre-commit-hooks-9262e31316a16180044e0e28a2740238f8aef5c4.tar.xz pre-commit-hooks-9262e31316a16180044e0e28a2740238f8aef5c4.zip |
Merging upstream version 4.3.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit_hooks/sort_simple_yaml.py')
-rw-r--r-- | pre_commit_hooks/sort_simple_yaml.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/pre_commit_hooks/sort_simple_yaml.py b/pre_commit_hooks/sort_simple_yaml.py index 39f683e..116b5c1 100644 --- a/pre_commit_hooks/sort_simple_yaml.py +++ b/pre_commit_hooks/sort_simple_yaml.py @@ -17,16 +17,16 @@ We assume a strict subset of YAML that looks like: In other words, we don't sort deeper than the top layer, and might corrupt complicated YAML files. """ +from __future__ import annotations + import argparse -from typing import List -from typing import Optional from typing import Sequence QUOTES = ["'", '"'] -def sort(lines: List[str]) -> List[str]: +def sort(lines: list[str]) -> list[str]: """Sort a YAML file in alphabetical order, keeping blocks together. :param lines: array of strings (without newlines) @@ -44,7 +44,7 @@ def sort(lines: List[str]) -> List[str]: return new_lines -def parse_block(lines: List[str], header: bool = False) -> List[str]: +def parse_block(lines: list[str], header: bool = False) -> list[str]: """Parse and return a single block, popping off the start of `lines`. If parsing a header block, we stop after we reach a line that is not a @@ -60,7 +60,7 @@ def parse_block(lines: List[str], header: bool = False) -> List[str]: return block_lines -def parse_blocks(lines: List[str]) -> List[List[str]]: +def parse_blocks(lines: list[str]) -> list[list[str]]: """Parse and return all possible blocks, popping off the start of `lines`. :param lines: list of lines @@ -77,7 +77,7 @@ def parse_blocks(lines: List[str]) -> List[List[str]]: return blocks -def first_key(lines: List[str]) -> str: +def first_key(lines: list[str]) -> str: """Returns a string representing the sort key of a block. The sort key is the first YAML key we encounter, ignoring comments, and @@ -99,7 +99,7 @@ def first_key(lines: List[str]) -> str: return '' # not actually reached in reality -def main(argv: Optional[Sequence[str]] = None) -> int: +def main(argv: Sequence[str] | None = None) -> int: parser = argparse.ArgumentParser() parser.add_argument('filenames', nargs='*', help='Filenames to fix') args = parser.parse_args(argv) |