fix: resolve all 64 mypy errors across backend

- Add dict[str, Any] / list[Any] type params throughout (fingerprint, models, schemas, scanner, status_checker)
- Add return type annotations to all route functions (nodes, edges, canvas, scan, auth, status, main)
- Fix no-any-return in security.py: cast pwd/jwt results to bool/str explicitly
- Fix canvas.py: use model_validate() for NodeResponse/EdgeResponse, rename db_node/db_edge upsert vars
- Fix scheduler.py: rename 'result' → 'check_result' to avoid type collision
- Fix get_db() return type: AsyncGenerator[AsyncSession, None]
- Add types-PyYAML for yaml import stubs
- Fix scanner.py: remove unnecessary type: ignore comment (nmap has stubs)
- Fix scan.py: wrap scalars().all() with list() for Sequence→list compatibility
This commit is contained in:
Pouzor
2026-03-07 15:48:41 +01:00
parent 1811afa749
commit 974e782057
17 changed files with 94 additions and 71 deletions
+6 -6
View File
@@ -28,19 +28,19 @@ async def _run_status_checks() -> None:
if not node.check_method:
continue
try:
result = await check_node(node.check_method, node.check_target, node.ip)
check_result = await check_node(node.check_method, node.check_target, node.ip)
async with AsyncSessionLocal() as db:
n = await db.get(Node, node.id)
if n:
n.status = result["status"]
n.response_time_ms = result["response_time_ms"]
n.last_seen = datetime.now(UTC) if result["status"] == "online" else n.last_seen
n.status = check_result["status"]
n.response_time_ms = check_result["response_time_ms"]
n.last_seen = datetime.now(UTC) if check_result["status"] == "online" else n.last_seen
await db.commit()
await broadcast_status(
node_id=node.id,
status=result["status"],
status=check_result["status"],
checked_at=datetime.now(UTC).isoformat(),
response_time_ms=result["response_time_ms"],
response_time_ms=check_result["response_time_ms"],
)
except Exception as exc:
logger.error("Status check failed for node %s: %s", node.id, exc)
+5 -4
View File
@@ -9,22 +9,23 @@ pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
def verify_password(plain: str, hashed: str) -> bool:
return pwd_context.verify(plain, hashed)
return bool(pwd_context.verify(plain, hashed))
def hash_password(password: str) -> str:
return pwd_context.hash(password)
return str(pwd_context.hash(password))
def create_access_token(subject: str) -> str:
expire = datetime.now(UTC) + timedelta(minutes=settings.access_token_expire_minutes)
payload = {"sub": subject, "exp": expire}
return jwt.encode(payload, settings.secret_key, algorithm=settings.algorithm)
return str(jwt.encode(payload, settings.secret_key, algorithm=settings.algorithm))
def decode_token(token: str) -> str | None:
try:
payload = jwt.decode(token, settings.secret_key, algorithms=[settings.algorithm])
return payload.get("sub")
sub = payload.get("sub")
return str(sub) if sub is not None else None
except JWTError:
return None