From: Andrew Grimberg Date: Tue, 10 Oct 2023 13:13:21 +0000 (-0700) Subject: Refactor: Add annotations to schema validator X-Git-Tag: v0.37.7~2^2~2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F37%2F72237%2F1;p=releng%2Flftools.git Refactor: Add annotations to schema validator Issue: RELENG-4933 Signed-off-by: Andrew Grimberg Change-Id: I1b13c1ad1ad825cf29718dd15c0cc56c8a4a55cc --- diff --git a/lftools/schema.py b/lftools/schema.py index e3d67b99..6b25fc2b 100644 --- a/lftools/schema.py +++ b/lftools/schema.py @@ -9,15 +9,16 @@ ############################################################################## """Verify YAML Schema.""" -from __future__ import print_function +from __future__ import annotations, print_function import logging +from typing import Dict import jsonschema import yaml -def check_schema_file(yamlfile, schemafile): +def check_schema_file(yamlfile: str, schemafile: str) -> None: """Verify YAML Schema. YAMLFILE: Release YAML file to be validated. @@ -25,17 +26,19 @@ def check_schema_file(yamlfile, schemafile): SCHEMAFILE: SCHEMA file to validate against. """ with open(yamlfile) as _: - yaml_file = yaml.safe_load(_) + yaml_file: Dict = yaml.safe_load(_) with open(schemafile) as _: - schema_file = yaml.safe_load(_) + schema_file: Dict = yaml.safe_load(_) # Load the schema - validation = jsonschema.Draft4Validator(schema_file, format_checker=jsonschema.FormatChecker()) + validation: jsonschema.Draft4Validator = jsonschema.Draft4Validator( + schema_file, format_checker=jsonschema.FormatChecker() + ) validation.iter_errors(yaml_file) # Look for errors - errors = 0 + errors: int = 0 for error in validation.iter_errors(yaml_file): errors += 1 logging.error(error)