Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply PEP 585 changes #5

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions models_validator/validate.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"] = (
Expand Down Expand Up @@ -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"]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down