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

This commit is contained in:
Krzysztof Rudnicki 2025-11-30 15:08:21 +01:00
parent 5cec131ebe
commit 82101ae4e4
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.""" """Chess engine wrapper for the C-based random/scoring engine."""
import json
import os import os
import subprocess import subprocess
@ -129,14 +130,12 @@ class RandomEngine:
out = self._call_engine(args, timeout=max(0.1, time_budget_sec)) out = self._call_engine(args, timeout=max(0.1, time_budget_sec))
# Try to parse the engine's JSON explanation # Try to parse the engine's JSON explanation
import json as _json
cand_score = 0.0 cand_score = 0.0
best_move: chess.Move | None = None best_move: chess.Move | None = None
cand_expl = out cand_expl = out
best_expl = out best_expl = out
try: try:
data = _json.loads(out) data = json.loads(out)
# candidate score if provided # candidate score if provided
analyze = data.get("analyze") or {} analyze = data.get("analyze") or {}
cs = analyze.get("candidate_score") cs = analyze.get("candidate_score")
@ -152,8 +151,8 @@ class RandomEngine:
except Exception: except Exception:
best_move = None best_move = None
# Store compact explanations for debugging # Store compact explanations for debugging
cand_expl = _json.dumps(analyze, ensure_ascii=False) cand_expl = json.dumps(analyze, ensure_ascii=False)
best_expl = _json.dumps( best_expl = json.dumps(
{ {
"chosen_index": data.get("chosen_index"), "chosen_index": data.get("chosen_index"),
"chosen_move": data.get("chosen_move"), "chosen_move": data.get("chosen_move"),

View File

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

View File

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