Enable PLC0415: move imports to top-level, allow late imports in tests

This commit is contained in:
Krzysztof kuhy Rudnicki 2025-11-30 15:08:21 +01:00
parent 3fcc7b62d9
commit dc34c0f9f3
3 changed files with 6 additions and 8 deletions

View File

@ -1,5 +1,6 @@
"""Chess engine wrapper for the C-based random/scoring engine."""
import json
import os
import subprocess
@ -129,14 +130,12 @@ class RandomEngine:
out = self._call_engine(args, timeout=max(0.1, time_budget_sec))
# Try to parse the engine's JSON explanation
import json as _json
cand_score = 0.0
best_move: chess.Move | None = None
cand_expl = out
best_expl = out
try:
data = _json.loads(out)
data = json.loads(out)
# candidate score if provided
analyze = data.get("analyze") or {}
cs = analyze.get("candidate_score")
@ -152,8 +151,8 @@ class RandomEngine:
except Exception:
best_move = None
# Store compact explanations for debugging
cand_expl = _json.dumps(analyze, ensure_ascii=False)
best_expl = _json.dumps(
cand_expl = json.dumps(analyze, ensure_ascii=False)
best_expl = json.dumps(
{
"chosen_index": data.get("chosen_index"),
"chosen_move": data.get("chosen_move"),

View File

@ -1,6 +1,7 @@
"""Main entry point for the Lichess bot."""
import argparse
import datetime
import json
import logging
import os
@ -96,8 +97,6 @@ def run_bot(log_level: str = "INFO", decline_correspondence: bool = False) -> No
"createdAtDate"
)
if created_ms:
import datetime
game_date_iso = datetime.datetime.utcfromtimestamp(
int(created_ms) / 1000
).strftime("%Y.%m.%d")

View File

@ -58,7 +58,6 @@ ignore = [
"FBT003", # Boolean positional value - common pattern
"ARG001", # Unused function argument - often needed for API compatibility
"ARG002", # Unused method argument - often needed for API compatibility
"PLC0415", # import-outside-top-level - sometimes necessary
"N816", # mixed-case-variable-in-global-scope - often constants
"N806", # non-lowercase-variable - sometimes intentional
"N803", # invalid-argument-name - chess notation uses uppercase
@ -100,6 +99,7 @@ unfixable = []
]
"**/test_*.py" = [
"S101", # Allow assert in tests
"PLC0415", # Allow late imports for test isolation
]
"**/conftest.py" = [
"D100", # Allow missing module docstring