diff --git a/models_validator/validate.py b/models_validator/validate.py index f7bc6685..af5c45ed 100644 --- a/models_validator/validate.py +++ b/models_validator/validate.py @@ -1,6 +1,6 @@ import re import sys -from typing import Any, Dict, List, Optional, Tuple, Union, cast +from typing import Any, cast import simplejson as json import yaml @@ -63,7 +63,7 @@ class Checker: def __init__(self, filepath: str) -> None: with open(filepath, "rb") as x: self.models = yaml.safe_load(x.read()) - self.errors: List[str] = [] + self.errors: list[str] = [] def run_check(self) -> None: self._run_checks() @@ -112,13 +112,13 @@ def check_field( self, collection: str, field_name: str, - field: Union[str, Dict[str, Any]], + field: str | dict[str, Any], nested: bool = False, ) -> None: collectionfield = f"{collection}{KEYSEPARATOR}{field_name}" if isinstance(field, str): - field = cast(Dict[str, Any], {"type": field}) + field = cast(dict[str, Any], {"type": field}) if nested: field["restriction_mode"] = ( @@ -257,8 +257,8 @@ def validate_value_for_type( raise NotImplementedError(type_str) def check_relation( - self, collection: str, field_name: str, field: Dict[str, Any] - ) -> Optional[str]: + self, collection: str, field_name: str, field: dict[str, Any] + ) -> str | None: collectionfield = f"{collection}{KEYSEPARATOR}{field_name}" to = field["to"] @@ -293,7 +293,7 @@ def check_relation( def check_reverse( self, from_collectionfield: str, to_collectionfield: str - ) -> Optional[str]: + ) -> str | None: to_unified = [] # a list of target collectionfields (unififed with all # the different possibilities for the 'to' field) from the (expected) # relation in to_collectionfield. The from_collectionfield must be in this @@ -322,7 +322,7 @@ def check_reverse( return f"{from_collectionfield} points to {to_collectionfield}, but {to_collectionfield} does not point back." return None - def split_collectionfield(self, collectionfield: str) -> Tuple[str, str]: + def split_collectionfield(self, collectionfield: str) -> tuple[str, str]: parts = collectionfield.split(KEYSEPARATOR) return parts[0], parts[1]