diff --git a/custom_json_diff/lib/custom_diff.py b/custom_json_diff/lib/custom_diff.py index 4db197a..40869b6 100644 --- a/custom_json_diff/lib/custom_diff.py +++ b/custom_json_diff/lib/custom_diff.py @@ -108,7 +108,7 @@ def generate_bom_diff(bom: BomDicts, commons: BomDicts, common_refs: Dict) -> Di case _: diff_summary["components"]["other_components"].append(i.to_dict()) #type: ignore diff_summary["misc_data"] = (bom.misc_data - commons.misc_data).to_dict() - diff_summary["components"] = filter_empty(bom.options.include_empty, diff_summary["components"]) + diff_summary["components"] = filter_empty(bom.options.include_empty, diff_summary["components"]) #type: ignore return filter_empty(commons.options.include_empty, diff_summary) diff --git a/custom_json_diff/lib/custom_diff_classes.py b/custom_json_diff/lib/custom_diff_classes.py index 6dabf50..a18d8ad 100644 --- a/custom_json_diff/lib/custom_diff_classes.py +++ b/custom_json_diff/lib/custom_diff_classes.py @@ -2,7 +2,7 @@ import re from copy import deepcopy from dataclasses import dataclass, field -from typing import Dict, List, Set, Tuple +from typing import Dict, List, Optional, Set, Tuple from json_flatten import unflatten # type: ignore @@ -230,9 +230,9 @@ def __init__(self, dep: Dict, options: "Options"): self.ref = dep.get("ref", "") self._deps = Array(dep.get("dependsOn", [])) # deprecated - self.original_data = {} + self.original_data: Dict = {} self.ref_no_version, self._deps_no_version = import_bom_dependency( - dep, options.allow_new_versions) if options.allow_new_versions else "", [] + dep, options.allow_new_versions) if options.allow_new_versions else "", Array([]) self.options = options def __eq__(self, other): @@ -465,7 +465,7 @@ def to_dict(self): class BomVdr: """Class for holding bom vulnerability data""" - def __init__(self, data: Dict = None, options: "Options" = Options(), **kwargs): + def __init__(self, data: Optional[Dict] = None, options: "Options" = Options(), **kwargs): if not data: data = {} self.options = options diff --git a/custom_json_diff/lib/utils.py b/custom_json_diff/lib/utils.py index 98f132c..a147ff8 100644 --- a/custom_json_diff/lib/utils.py +++ b/custom_json_diff/lib/utils.py @@ -4,7 +4,7 @@ import re import sys from datetime import date, datetime -from typing import Any, Dict, List, LiteralString, TYPE_CHECKING +from typing import Any, Dict, List, TYPE_CHECKING import packageurl import semver @@ -106,7 +106,7 @@ def export_html_report(outfile: str, diffs: Dict, options: "Options", status: in template_file = options.report_template or os.path.join(os.path.dirname(os.path.realpath(__file__)), f"{options.preconfig_type}_diff_template.j2") template = file_read(template_file) jinja_env = Environment(autoescape=True) - jinja_tmpl = jinja_env.from_string(template) + jinja_tmpl = jinja_env.from_string(str(template)) if options.preconfig_type == "bom": report_result = render_bom_template(diffs, jinja_tmpl, options, stats_summary, status) else: @@ -115,7 +115,7 @@ def export_html_report(outfile: str, diffs: Dict, options: "Options", status: in success_msg=f"HTML report generated: {outfile}") -def file_read(filename: LiteralString | str | bytes, binary: bool = False, error_msg: str = "", log: logging.Logger = logger) -> str | bytes: +def file_read(filename: str | bytes, binary: bool = False, error_msg: str = "", log: logging.Logger = logger) -> str | bytes: try: if binary: with open(filename, "rb") as f: @@ -130,7 +130,7 @@ def file_read(filename: LiteralString | str | bytes, binary: bool = False, error return "" -def file_write(filename: LiteralString | str | bytes, contents, error_msg: str = "", success_msg: str = "", log: logging.Logger = logger) -> None: +def file_write(filename: str | bytes, contents, error_msg: str = "", success_msg: str = "", log: logging.Logger = logger) -> None: try: with open(filename, "w", encoding="utf-8") as f: f.write(contents) @@ -170,7 +170,7 @@ def get_sort_key_list(data: List[Dict], sort_keys: List): def import_config(config: str) -> Dict: file_data = file_read(config, False, f"Unable to locate {config}.") try: - toml_data = toml.loads(file_data) + toml_data = toml.loads(str(file_data)) if toml_data.get("preset_settings") and toml_data["preset_settings"].get("type", "") not in { "bom", "csaf"}: raise ValueError("Invalid preset type.")