summaryrefslogtreecommitdiffstats
path: root/pre_commit_hooks/sort_simple_yaml.py
diff options
context:
space:
mode:
Diffstat (limited to 'pre_commit_hooks/sort_simple_yaml.py')
-rw-r--r--pre_commit_hooks/sort_simple_yaml.py14
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)