feat: MAINT-001 - Fix Ruff violations across all Python source

This commit is contained in:
Dobromir Popov
2026-07-14 14:17:23 +03:00
parent a0f28b5631
commit 4eeec7fa7f
22 changed files with 30 additions and 52 deletions

View File

@@ -3,7 +3,6 @@
import http.server
import hashlib
import json
import os
from collections import Counter
from dataclasses import dataclass
import threading
@@ -62,7 +61,7 @@ class _GatewayHTTPServer(http.server.HTTPServer):
class _GatewayHandler(http.server.BaseHTTPRequestHandler):
def log_message(self, fmt, *args): # noqa: suppress request logs in tests
def log_message(self, fmt, *args): # suppress request logs in tests
pass
def do_GET(self):

View File

@@ -144,7 +144,7 @@ def _cmd_default(args) -> int:
print("\nSetup cancelled.")
return 1
save_config(cfg)
print(f"\nConfig saved to ~/.config/meshnet/config.json\n")
print("\nConfig saved to ~/.config/meshnet/config.json\n")
# Apply CLI overrides on top of saved config
overrides: dict = {}
@@ -198,7 +198,7 @@ def _cmd_default(args) -> int:
def _cmd_models(args) -> int:
"""List curated models (with optional HF Hub browse)."""
from .wizard import print_models_table, _browse_hf_interactive
from .wizard import print_models_table
if args.browse:
from .model_catalog import browse_hf_hub

View File

@@ -5,7 +5,6 @@ from __future__ import annotations
import os
import sys
import time
from collections import deque
from typing import TYPE_CHECKING
if TYPE_CHECKING:
@@ -114,7 +113,7 @@ def run_dashboard(node, config: dict, start_time: float) -> None:
return
try:
from rich.live import Live # type: ignore[import]
from rich.live import Live # type: ignore[import] # noqa: F401
_run_rich_dashboard(node, config, start_time)
except ImportError:
@@ -126,7 +125,6 @@ def _build_rich_renderable(
):
from rich.table import Table # type: ignore[import]
from rich.panel import Panel # type: ignore[import]
from rich.columns import Columns # type: ignore[import]
from rich.text import Text # type: ignore[import]
uptime = time.monotonic() - start_time
@@ -178,8 +176,8 @@ def _build_rich_renderable(
f"Tokens/sec {tps_bar} {tps:.1f} t/s (EMA)",
f"Requests {req_count:,} served",
f"Success {stats['success_rate']:.1f}% failed {stats['failed_requests']:,} queue {stats['queue_depth']}",
f"Peers 0 connected (gossip: US-017)",
f"TAI earned 0.00 TAI (payments: US-006)",
"Peers 0 connected (gossip: US-017)",
"TAI earned 0.00 TAI (payments: US-006)",
f"Uptime {_format_uptime(uptime)}",
"",
"[q] quit [c] compact view",

View File

@@ -105,7 +105,7 @@ class _StubHTTPServer(http.server.HTTPServer):
class _StubHandler(http.server.BaseHTTPRequestHandler):
def log_message(self, fmt, *args): # noqa: suppress request logs in tests
def log_message(self, fmt, *args): # suppress request logs in tests
pass
def do_POST(self):

View File

@@ -19,7 +19,6 @@ from .model_backend import (
InsufficientVRAMError,
KVCacheMiss,
MissingModelDependencyError,
Quantization,
TailTokenResult,
TorchModelShard,
_tensor_from_bfloat16_bytes,
@@ -46,7 +45,7 @@ class _DirectRequestUncertainError(ConnectionError):
"""A direct request may have reached the downstream node but did not finish."""
from .server import (
from .server import ( # noqa: E402
_WIRE_VERSION,
_parse_shape,
_validate_activation_body,
@@ -399,7 +398,7 @@ class _TorchHandler(http.server.BaseHTTPRequestHandler):
# Finite responses below provide Content-Length; streams are chunked.
protocol_version = "HTTP/1.1"
def log_message(self, fmt, *args): # noqa: suppress request logs in tests
def log_message(self, fmt, *args): # suppress request logs in tests
pass
def _request_id(self) -> str:

View File

@@ -2,7 +2,6 @@
from __future__ import annotations
import sys
import urllib.error
import urllib.request
from pathlib import Path

View File

@@ -7,7 +7,6 @@ from __future__ import annotations
import logging
import socket
import threading
from typing import Callable
log = logging.getLogger(__name__)

View File

@@ -3,9 +3,7 @@
from __future__ import annotations
import datetime
import hashlib
import ipaddress
import json
import os
import socket
import ssl

View File

@@ -4,7 +4,6 @@ from __future__ import annotations
import argparse
import logging
import sys
import time
from pathlib import Path

View File

@@ -16,8 +16,8 @@ import threading
import time
import urllib.error
import urllib.request
from dataclasses import dataclass, field
from typing import Any, Callable
from dataclasses import dataclass
from typing import Callable
@dataclass

View File

@@ -26,7 +26,7 @@ import random
import sqlite3
import threading
import time
from dataclasses import dataclass, field
from dataclasses import dataclass
from typing import Any, Iterable

View File

@@ -53,10 +53,6 @@ from typing import Any
from .accounts import DEFAULT_ACCOUNTS_DB_PATH, AccountStore
from .auth import is_validator_token, sign_hive_request, verify_hive_request
from .capability import (
DEFAULT_POLICY as DEFAULT_CAPABILITY_POLICY,
POLICY_COMPAT,
POLICY_ENFORCE,
STATE_ABSENT,
STATE_ADMITTED,
STATE_MODEL_MISMATCH,
STATE_SHARD_MISMATCH,
@@ -69,7 +65,7 @@ from .capability import (
)
from .wallet_proof import binding_message, verify_wallet_signature
from .billing import DEFAULT_BILLING_DB_PATH, BillingLedger
from .calibration import DEFAULT_CALIBRATION_DB_PATH, ToplocCalibrationStore
from .calibration import ToplocCalibrationStore
from .hf_pricing import DEFAULT_HF_PRICING_LOG_DB_PATH, HfPricingLog, refresh_preset_price
from .gossip import NodeGossip
from .logging_setup import tracker_logger
@@ -2566,8 +2562,8 @@ def _estimate_prompt_tokens(body: dict) -> int | None:
def _requested_completion_token_limit(body: dict) -> int | None:
for field in ("max_completion_tokens", "max_tokens"):
value = body.get(field)
for key in ("max_completion_tokens", "max_tokens"):
value = body.get(key)
if isinstance(value, bool):
return None
if isinstance(value, (int, float)):
@@ -2948,7 +2944,7 @@ class _TrackerHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
class _TrackerHandler(http.server.BaseHTTPRequestHandler):
def log_message(self, fmt, *args): # noqa: suppress request logs in tests
def log_message(self, fmt, *args): # suppress request logs in tests
pass
def _send_json(self, status: int, data: dict, headers: dict[str, str] | None = None) -> None:
@@ -7069,10 +7065,6 @@ class TrackerServer:
shard_end = int(payload["shard_end"]) if payload.get("shard_end") is not None else None
except (TypeError, ValueError):
return
try:
friendly_name = _normalize_friendly_name(payload.get("friendly_name"))
except ValueError:
friendly_name = None
# The replicated payload is the raw registration body, so the follower can
# resolve precision exactly as the leader did -- including telling a legacy
# absent `quantization` from a declared one. Dropping these fields here

View File

@@ -545,6 +545,8 @@ def _post_json(url: str, payload: dict, timeout: float = 5.0) -> dict:
__all__ = [
"ToplocAuditConfig",
"ToplocProofClaim",
"ToplocVerificationResult",
"verify_activation_proofs_detailed",
"ValidatorProcess",
"AdaptiveAuditSampler",
"AuditRateConfig",