Skip to content

Commit a75ae8e

Browse files
committed
fix: type errors
1 parent 7263af2 commit a75ae8e

5 files changed

Lines changed: 21 additions & 14 deletions

File tree

examples/analytic_extractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# Prune an input string to remove any non-analytic text
1313
# This assumes that all analytics start the <h4> html block
14-
STRING_RE = "Analytic(\s|.)*"
14+
STRING_RE = r"Analytic(\s|.)*"
1515

1616

1717
def pruneString(in_string):

mitreattack/navlayers/core/layerobj.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ def __init__(self, name, domain):
5252
@property
5353
def version(self):
5454
"""Getter for version."""
55-
if self.__versions != UNSETVALUE:
55+
if self.__versions != UNSETVALUE and not isinstance(self.__versions, str):
5656
return self.__versions.layer
5757

5858
@version.setter
5959
def version(self, version):
6060
typeChecker(type(self).__name__, version, str, "version")
6161
categoryChecker(type(self).__name__, version, ["3.0", "4.0", "4.1", "4.2", "4.3"], "version")
62-
if self.__versions is UNSETVALUE:
62+
if self.__versions is UNSETVALUE or isinstance(self.__versions, str):
6363
self.__versions = Versions()
6464
self.__versions.layer = version
6565

@@ -350,7 +350,7 @@ def links(self):
350350
@links.setter
351351
def links(self, links):
352352
typeChecker(type(self).__name__, links, list, "links")
353-
if not handle_object_placement(self.__links, links, Link):
353+
if not handle_object_placement(self.__links, links, Link) or isinstance(self.__links, str):
354354
self.__links = []
355355
entry = ""
356356
try:
@@ -418,21 +418,21 @@ def get_dict(self):
418418

419419
if self.description:
420420
temp["description"] = self.description
421-
if self.versions:
421+
if self.versions and not isinstance(self.versions, str):
422422
temp["versions"] = self.versions.get_dict()
423-
if self.filters:
423+
if self.filters and not isinstance(self.filters, str):
424424
temp["filters"] = self.filters.get_dict()
425425
if self.sorting:
426426
temp["sorting"] = self.sorting
427-
if self.layout:
427+
if self.layout and not isinstance(self.layout, str):
428428
temp["layout"] = self.layout.get_dict()
429429
if self.hideDisabled is not None:
430430
temp["hideDisabled"] = self.hideDisabled
431-
if self.techniques:
431+
if self.techniques and isinstance(self.techniques, list):
432432
temp["techniques"] = [x.get_dict() for x in self.techniques]
433-
if self.gradient:
433+
if self.gradient and not isinstance(self.gradient, str):
434434
temp["gradient"] = self.gradient.get_dict()
435-
if self.legendItems:
435+
if self.legendItems and isinstance(self.legendItems, list):
436436
temp["legendItems"] = [x.get_dict() for x in self.legendItems]
437437
if self.showTacticRowBackground is not None:
438438
temp["showTacticRowBackground"] = self.showTacticRowBackground
@@ -444,7 +444,7 @@ def get_dict(self):
444444
temp["selectSubtechniquesWithParent"] = self.selectSubtechniquesWithParent
445445
if self.selectVisibleTechniques is not None:
446446
temp["selectVisibleTechniques"] = self.selectVisibleTechniques
447-
if self.metadata:
447+
if self.metadata and isinstance(self.metadata, list):
448448
temp["metadata"] = [x.get_dict() for x in self.metadata]
449449
return temp
450450

mitreattack/navlayers/generators/usage_generator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import copy
44
from itertools import chain
5+
from typing import Any
56

67
from stix2 import Filter
78

@@ -149,7 +150,9 @@ def generate_layer(self, match):
149150
raise StixObjectIsNotValid
150151
a_id = get_attack_id(matched_obj)
151152
processed_listing = self.generate_technique_data(raw_data)
152-
raw_layer = dict(name=f"{matched_obj['name']} ({matched_obj['id']})", domain=self.domain + "-attack")
153+
raw_layer: dict[str, Any] = dict(
154+
name=f"{matched_obj['name']} ({matched_obj['id']})", domain=self.domain + "-attack"
155+
)
153156
raw_layer["techniques"] = processed_listing
154157
output_layer = Layer(raw_layer)
155158
if matched_obj["type"] != "x-mitre-data-component":

mitreattack/release_info.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231

232232

233233
def get_attack_version(
234-
domain: str, stix_version: str = "2.0", stix_file: str = None, stix_content: bytes = None
234+
domain: str, stix_version: str = "2.0", stix_file: Optional[str] = None, stix_content: Optional[bytes] = None
235235
) -> Optional[str]:
236236
"""Determine the version of ATT&CK based on either a file or contents of a file.
237237
@@ -277,6 +277,9 @@ def get_attack_version(
277277
stix_hash_data = STIX20
278278
elif stix_version == "2.1":
279279
stix_hash_data = STIX21
280+
else:
281+
logger.error(f"Invalid stix_version given: {stix_version}")
282+
return None
280283

281284
releases = {}
282285
if domain == "enterprise-attack":

tests/changelog/test_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import json
8+
from collections.abc import Callable
89
from pathlib import Path
910
from typing import Any, Dict, List, Optional, Union
1011

@@ -184,7 +185,7 @@ def assert_diffstix_data_structure_valid(diffstix_instance) -> None:
184185

185186

186187
def create_test_files_and_validate(
187-
file_paths: Dict[str, Union[str, Path]], validation_funcs: Dict[str, callable]
188+
file_paths: Dict[str, Union[str, Path]], validation_funcs: Dict[str, Callable]
188189
) -> None:
189190
"""Create test files and validate their contents.
190191

0 commit comments

Comments
 (0)