Skip to content

Commit 2cdf9f3

Browse files
committed
chore(cwe): define NOCWE to avoid repetition
1 parent 27d227d commit 2cdf9f3

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

codesectools/shared/cwe.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__(self) -> None:
9999
"Research Concepts": "1000.csv",
100100
}
101101
self.directory = USER_CACHE_DIR / "cwe"
102+
self.NOCWE = CWE(id=-1, name=" Missing or invalid CWE", description="None")
102103

103104
try:
104105
self.cwes = self.load()
@@ -162,7 +163,7 @@ def from_string(self, cwe_string: str) -> CWE:
162163
if match := re.search(r"[CWE|cwe]-(\d+)", cwe_string):
163164
return self.from_id(int(match.group(1)))
164165
else:
165-
return CWE(id=-1, name="Invalid CWE", description="None")
166+
return self.NOCWE
166167

167168
def from_id(self, cwe_id: int) -> CWE:
168169
"""Get a CWE by its identifier.
@@ -177,7 +178,7 @@ def from_id(self, cwe_id: int) -> CWE:
177178
try:
178179
return self.cwes[self.cwes.index(cwe_id)]
179180
except ValueError:
180-
return CWE(id=-1, name="Invalid CWE", description="None")
181+
return self.NOCWE
181182

182183

183184
CWEs = CWEsCollection()

0 commit comments

Comments
 (0)