Skip to content

Commit

Permalink
Typing.
Browse files Browse the repository at this point in the history
Signed-off-by: Caroline Russell <[email protected]>
  • Loading branch information
cerrussell committed Oct 7, 2024
1 parent 15faf37 commit 878ddcd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion custom_json_diff/lib/custom_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
8 changes: 4 additions & 4 deletions custom_json_diff/lib/custom_diff_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions custom_json_diff/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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.")
Expand Down

0 comments on commit 878ddcd

Please sign in to comment.