chore: type the doc, download and prose tests

mypy reported sixteen errors in these three test modules: untyped empty lists, unchecked re.search results, a release index named like the loop counter before it, and a read() override narrower than BytesIO's.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 15:47:20 +01:00
1 parent 48d88da168
commit 4630946656
3 files changed
+15 -13

No files matched your search

+10 -8
View File
@@ -41,7 +41,7 @@ _section = functools.partial(mdsections.section, stop=6)
def _table_rows(text: str) -> list[list[str]]:
rows = []
rows: list[list[str]] = []
rows.extend(
[cell.strip() for cell in line.strip().strip("|").split(" | ")]
for line in text.splitlines()
@@ -79,8 +79,9 @@ class TestSkeletonReadsTheResultShape(unittest.TestCase):
def _generated(text: str, name: str) -> str:
"""The body scripts/generate_installer_doc.py writes between the markers."""
return re.search(rf"(?s)<!-- generated: {name} -->\n(.*?)<!-- /generated: {name} -->",
text).group(1)
body = re.search(rf"(?s)<!-- generated: {name} -->\n(.*?)<!-- /generated: {name} -->", text)
assert body is not None, f"no generated: {name} markers"
return body.group(1)
class InstallerOutputExample(unittest.TestCase):
@@ -162,6 +163,7 @@ class InstallerOutputExample(unittest.TestCase):
split = re.search(r"(\d+) BIOS files \(([\d.]+) ([KMG]B)\)(?:,| and) (\d+) game data "
r"files \(([\d.]+) ([KMG]B)\)", text)
self.assertIsNotNone(split, "a categorized list says its BIOS files and game data")
assert split is not None
bios, bios_size, bios_unit, games, game_size, game_unit = split.groups()
# The data files in the one total, the third kind.
data = re.search(r"and (\d+) data files \(([\d.]+) ([KMG]B)\)", text)
@@ -279,7 +281,7 @@ class RequirementFieldsTable(unittest.TestCase):
the native dict, the fields that make a platform YAML reversible, were
named nowhere a scraper author reads first."""
def test_every_field_and_native_key_is_listed(self):
def test_every_field_and_native_key_is_listed(self) -> None:
from dataclasses import fields
from scraper.base_scraper import BiosRequirement
@@ -585,7 +587,7 @@ class ToolsRunOnTheStatedFloor(unittest.TestCase):
return isinstance(node, ast.Name) and node.id in self.TYPES
def _runtime_unions(self, tree: ast.AST) -> list[int]:
annotations = set()
annotations: set[int] = set()
for node in ast.walk(tree):
for field in ("annotation", "returns"):
value = getattr(node, field, None)
@@ -1518,8 +1520,8 @@ def stale_options(text: str, default: str | None) -> list[str]:
commands = []
for block in FENCED.findall(text):
commands += [line for line in block.splitlines()[1:-1] if not line.lstrip().startswith("#")]
page_scripts = {_owner(command) for command in commands} - {None}
stale = []
page_scripts = {owner for command in commands if (owner := _owner(command))}
stale: list[str] = []
for line in commands:
for part in re.split(r"\s+&&\s+|;\s+|\|\s+(?!sh\b)", line):
if not part or part.lstrip().startswith(FOREIGN_COMMANDS):
@@ -1565,7 +1567,7 @@ def _literals() -> str:
texts = []
for node in ast.walk(ast.parse((ROOT / "install.py").read_text(encoding="utf-8"))):
if isinstance(node, ast.JoinedStr):
texts.append("".join(value.value if isinstance(value, ast.Constant) else "\x01"
texts.append("".join(str(value.value) if isinstance(value, ast.Constant) else "\x01"
for value in node.values))
elif isinstance(node, ast.Constant) and isinstance(node.value, str):
texts.append(node.value)
+4 -4
View File
@@ -340,8 +340,8 @@ class ReleaseServer:
self.httpd = http.server.ThreadingHTTPServer(("127.0.0.1", 0), handler)
self.base = f"http://127.0.0.1:{self.httpd.server_address[1]}"
index = self.root / "repos" / "Abdess" / "retrobios" / "releases"
index.mkdir(parents=True)
releases = self.root / "repos" / "Abdess" / "retrobios" / "releases"
releases.mkdir(parents=True)
assets = [
{
"name": name,
@@ -350,7 +350,7 @@ class ReleaseServer:
}
for name in self.names + ["SHA256SUMS.txt"]
]
self.index = index / "latest"
self.index = releases / "latest"
self.index.write_text(json.dumps({"assets": assets}))
threading.Thread(target=self.httpd.serve_forever, daemon=True).start()
@@ -721,7 +721,7 @@ class AProgressBarOnlyOnATerminal(unittest.TestCase):
return False
class Cut(Body):
def read(self, size: int = -1) -> bytes:
def read(self, size: int | None = -1) -> bytes:
raise http.client.IncompleteRead(b"pa")
answers = [Cut(b""), Body(b"packed")]
+1 -1
View File
@@ -365,7 +365,7 @@ class ProfilesStateFactsAboutOtherProjects(unittest.TestCase):
class NoClauseSemicolons(unittest.TestCase):
def _check(self, files: list[Path], extract) -> None:
offenders = []
offenders: list[str] = []
for path in files:
text = path.read_text(encoding="utf-8")
offenders.extend(