Skip to content

Commit 8035752

Browse files
authored
refactor: fix "Any" type and mypy errors in data_sources/ (#2395)
1 parent 611c0bf commit 8035752

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

cve_bin_tool/data_sources/curl_source.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
import logging
99
import re
1010
from pathlib import Path
11-
from typing import Any
1211

1312
import aiohttp
14-
from bs4 import BeautifulSoup
13+
from bs4 import BeautifulSoup, NavigableString, ResultSet
1514

1615
from cve_bin_tool.async_utils import FileIO, RateLimiter
1716
from cve_bin_tool.data_sources import (
@@ -85,9 +84,9 @@ async def download_curl_version(self, session: RateLimiter, version: str) -> Non
8584
html = await response.text()
8685
soup = BeautifulSoup(html, "html.parser")
8786
table = soup.find("table")
88-
if not table:
87+
if not table or isinstance(table, NavigableString):
8988
return
90-
headers = table.find_all("th")
89+
headers: ResultSet | list = table.find_all("th")
9190
headers = list(map(lambda x: x.text.strip().lower(), headers))
9291
self.LOGGER.debug(headers)
9392
rows = table.find_all("tr")
@@ -103,7 +102,7 @@ async def download_curl_version(self, session: RateLimiter, version: str) -> Non
103102
async with FileIO(filepath, "w") as f:
104103
await f.write(json.dumps(json_data, indent=4))
105104

106-
def load_curl_version(self, version: str) -> dict[str, Any]:
105+
def load_curl_version(self, version: str) -> list[dict[str, str]]:
107106
"""
108107
Return the dict of CVE data for the given curl version.
109108
"""

cve_bin_tool/data_sources/nvd_source.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import re
1414
import sqlite3
1515
from pathlib import Path
16-
from typing import Any
1716

1817
import aiohttp
1918
from rich.progress import track
@@ -77,7 +76,7 @@ def __init__(
7776
self.cve_count = -1
7877
self.nvd_type = nvd_type
7978
self.incremental_update = incremental_update
80-
self.all_cve_entries: list[dict[str, Any]] | None = None
79+
self.all_cve_entries: list[dict[str, object]] | None = None
8180

8281
# store the nvd api key for use later
8382
self.nvd_api_key = nvd_api_key
@@ -170,7 +169,7 @@ def format_data(self, all_cve_entries):
170169

171170
return cve_data, affects_data
172171

173-
def parse_node(self, node: dict[str, Any]) -> list[dict[str, str]]:
172+
def parse_node(self, node: dict[str, list[dict[str, str]]]) -> list[dict[str, str]]:
174173
affects_list = []
175174
if "cpe_match" in node:
176175
for cpe_match in node["cpe_match"]:
@@ -280,7 +279,9 @@ def format_data_api2(self, all_cve_entries):
280279

281280
return cve_data, affects_data
282281

283-
def parse_node_api2(self, node: dict[str, Any]) -> list[dict[str, str]]:
282+
def parse_node_api2(
283+
self, node: dict[str, list[dict[str, str]]]
284+
) -> list[dict[str, str]]:
284285
affects_list = []
285286
if "cpeMatch" in node:
286287
for cpe_match in node["cpeMatch"]:
@@ -478,7 +479,7 @@ async def cache_update(
478479
with ErrorHandler(mode=self.error_mode, logger=self.LOGGER):
479480
raise SHAMismatch(f"{url} (have: {gotsha}, want: {sha})")
480481

481-
def load_nvd_year(self, year: int) -> dict[str, Any]:
482+
def load_nvd_year(self, year: int) -> dict[str, str | object]:
482483
"""
483484
Return the dict of CVE data for the given year.
484485
"""

0 commit comments

Comments
 (0)