Skip to content

Commit d054371

Browse files
authored
Fix some type hints
1 parent 9730dc1 commit d054371

1 file changed

Lines changed: 27 additions & 12 deletions

File tree

mitreattack/diffStix/changelog_helper.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ class DiffStix(object):
6666
def __init__(
6767
self,
6868
domains: List[str] = ["enterprise-attack", "mobile-attack", "ics-attack"],
69-
layers: List[str] = None,
69+
layers: Optional[List[str]] = None,
7070
unchanged: bool = False,
71-
old: str = "old",
71+
old: Optional[str] = "old",
7272
new: str = "new",
7373
show_key: bool = False,
7474
site_prefix: str = "",
@@ -944,7 +944,7 @@ def get_md_key(self) -> str:
944944

945945
return key
946946

947-
def get_markdown_string(self):
947+
def get_markdown_string(self) -> str:
948948
"""Return a markdown string summarizing detected differences."""
949949
logger.info("Generating markdown output")
950950
content = ""
@@ -1107,15 +1107,15 @@ def get_changes_dict(self):
11071107
return changes_dict
11081108

11091109

1110-
def has_subtechniques(stix_object: dict, subtechnique_relationships: List[dict]) -> bool:
1110+
def has_subtechniques(stix_object: dict, subtechnique_relationships: Dict[str, dict]) -> bool:
11111111
"""Return true or false depending on whether the SDO has sub-techniques.
11121112
11131113
Parameters
11141114
----------
11151115
stix_object : dict
11161116
An ATT&CK STIX Domain Object (SDO).
1117-
subtechnique_relationships : List[dict]
1118-
List of STIX Relationship Object (SRO) dictionaries.
1117+
subtechnique_relationships : Dict[str, dict]
1118+
Dictionary of STIX ID: Relationship Object (SRO).
11191119
11201120
Returns
11211121
-------
@@ -1198,7 +1198,7 @@ def cleanup_values(groupings: List[dict]) -> List[dict]:
11981198

11991199

12001200
def version_increment_is_valid(
1201-
old_version: AttackObjectVersion, new_version: AttackObjectVersion, section: str
1201+
old_version: AttackObjectVersion | None, new_version: AttackObjectVersion | None, section: str
12021202
) -> bool:
12031203
"""Validate version increment between old and new STIX objects.
12041204
@@ -1211,10 +1211,10 @@ def version_increment_is_valid(
12111211
12121212
Parameters
12131213
----------
1214-
old_version : AttackObjectVersion
1215-
Old version of an ATT&CK STIX Domain Object (SDO).
1216-
new_version : AttackObjectVersion
1217-
New version of an ATT&CK STIX Domain Object (SDO).
1214+
old_version : AttackObjectVersion | None
1215+
Old version of an ATT&CK STIX Domain Object (SDO). Can be None for additions.
1216+
new_version : AttackObjectVersion | None
1217+
New version of an ATT&CK STIX Domain Object (SDO). Can be None for deletions.
12181218
section : str
12191219
Section change type, e.g major_version_change, revocations, etc.
12201220
@@ -1242,6 +1242,11 @@ def version_increment_is_valid(
12421242

12431243
def is_major_version_change(old_version: AttackObjectVersion, new_version: AttackObjectVersion) -> bool:
12441244
"""Determine if the new version is a major change."""
1245+
if old_version is None or new_version is None:
1246+
return False
1247+
# Check if inputs are the correct type
1248+
if not isinstance(old_version, AttackObjectVersion) or not isinstance(new_version, AttackObjectVersion):
1249+
return False
12451250
next_major_num = old_version.major + 1
12461251
next_major_version = AttackObjectVersion(major=next_major_num, minor=0)
12471252
if new_version == next_major_version:
@@ -1251,6 +1256,11 @@ def is_major_version_change(old_version: AttackObjectVersion, new_version: Attac
12511256

12521257
def is_minor_version_change(old_version: AttackObjectVersion, new_version: AttackObjectVersion) -> bool:
12531258
"""Determine if the new version is a minor change."""
1259+
if old_version is None or new_version is None:
1260+
return False
1261+
# Check if inputs are the correct type
1262+
if not isinstance(old_version, AttackObjectVersion) or not isinstance(new_version, AttackObjectVersion):
1263+
return False
12541264
next_minor_num = old_version.minor + 1
12551265
next_minor_version = AttackObjectVersion(major=old_version.major, minor=next_minor_num)
12561266
if new_version == next_minor_version:
@@ -1260,6 +1270,11 @@ def is_minor_version_change(old_version: AttackObjectVersion, new_version: Attac
12601270

12611271
def is_other_version_change(old_version: AttackObjectVersion, new_version: AttackObjectVersion) -> bool:
12621272
"""Determine if the new version is an unexpected change."""
1273+
if old_version is None or new_version is None:
1274+
return False
1275+
# Check if inputs are the correct type
1276+
if not isinstance(old_version, AttackObjectVersion) or not isinstance(new_version, AttackObjectVersion):
1277+
return False
12631278
# either stayed the same or was a normal version change
12641279
if is_major_version_change(old_version=old_version, new_version=new_version):
12651280
return False
@@ -1903,7 +1918,7 @@ def get_new_changelog_md(
19031918
domains: List[str] = ["enterprise-attack", "mobile-attack", "ics-attack"],
19041919
layers: List[str] = layer_defaults,
19051920
unchanged: bool = False,
1906-
old: str = None,
1921+
old: Optional[str] = None,
19071922
new: str = "new",
19081923
show_key: bool = False,
19091924
site_prefix: str = "",

0 commit comments

Comments
 (0)