fix: use sys.platform guards so mypy passes on Windows (#7401)

mypy does not narrow on `platform.system()`, so Windows-based contributors
get 8 spurious attr-defined/unused-ignore errors from the termios and
resource imports. Switch to `sys.platform` comparisons, which mypy
understands natively, and drop the now-unneeded type-ignore comments.

Fixes #7400

Co-authored-by: Vidit Ostwal <110953813+Vidit-Ostwal@users.noreply.github.com>
This commit is contained in:
Modusensus
2026-09-14 17:08:50 +08:00
committed by GitHub
parent 9393a47f31
commit 7e80d94921
2 changed files with 12 additions and 11 deletions

View File

@@ -8,6 +8,7 @@ import json
import logging
import os
from pathlib import Path
import sys
import threading
import time
from typing import Any
@@ -77,14 +78,15 @@ class LanceDBStorage:
self._table_name = table_name
self._db = lancedb.connect(str(self._path))
try:
import resource
if sys.platform != "win32":
try:
import resource
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
if soft < 4096:
resource.setrlimit(resource.RLIMIT_NOFILE, (min(hard, 4096), hard))
except Exception: # noqa: S110
pass # Windows or already at the max hard limit — safe to ignore
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
if soft < 4096:
resource.setrlimit(resource.RLIMIT_NOFILE, (min(hard, 4096), hard))
except Exception: # noqa: S110
pass # Already at the max hard limit — safe to ignore
self._compact_every = compact_every
self._save_count = 0

View File

@@ -3,7 +3,6 @@
import contextvars
import json
from pathlib import Path
import platform
import re
import sys
import threading
@@ -175,11 +174,11 @@ def create_tool_function(crew: Crew, messages: list[LLMMessage]) -> Any:
def flush_input() -> None:
"""Flush any pending input from the user."""
if platform.system() == "Windows":
if sys.platform == "win32":
import msvcrt
while msvcrt.kbhit(): # type: ignore[attr-defined]
msvcrt.getch() # type: ignore[attr-defined]
while msvcrt.kbhit():
msvcrt.getch()
else:
import termios