Skip to content

Commit f2e14d2

Browse files
committed
chore: clean CodeQL baseline findings
1 parent 91c7ee8 commit f2e14d2

7 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/mcp_server_python_docs/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def _close_saved_stdout_fd() -> None:
2727
try:
2828
os.close(_saved_stdout_fd)
2929
except OSError:
30+
# Best-effort cleanup; the fd may already be closed during interpreter shutdown.
3031
pass
3132
finally:
3233
_saved_stdout_fd = None
@@ -515,6 +516,7 @@ def doctor() -> None:
515516
test_file.unlink()
516517
cache_writable = True
517518
except OSError:
519+
# Doctor reports the cache as not writable below.
518520
pass
519521
cache_ok = True # Not existing yet is OK (will be created on first build)
520522
cache_detail = str(cache_dir)

src/mcp_server_python_docs/detection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def detect_python_version() -> tuple[str, str]:
4444
logger.info("Detected Python %s from .python-version", version)
4545
return version, ".python-version file"
4646
except Exception:
47+
# The version file is optional; fall through to active interpreter probing.
4748
pass
4849

4950
# 2. python3 --version in PATH
@@ -60,6 +61,7 @@ def detect_python_version() -> tuple[str, str]:
6061
logger.info("Detected Python %s from python3 in PATH", version)
6162
return version, "python3 in PATH"
6263
except (FileNotFoundError, subprocess.TimeoutExpired, OSError):
64+
# python3 may be absent or too slow; fall through to the server runtime.
6365
pass
6466

6567
# 3. Server's own runtime

src/mcp_server_python_docs/ingestion/sphinx_json.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ def ingest_fjson_file(
508508
try:
509509
conn.rollback()
510510
except Exception:
511+
# Keep reporting the original ingestion failure if rollback also fails.
511512
pass
512513
return False
513514

src/mcp_server_python_docs/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,15 @@ async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
197197
error_log = cache_dir / "last-error.log"
198198
error_log.write_text(error_msg)
199199
except Exception:
200+
# Best-effort diagnostic write; preserve the original lifespan error.
200201
pass
201202
raise
202203
finally:
203204
if persistent_docs_cache is not None:
204205
try:
205206
persistent_docs_cache.close()
206207
except Exception:
208+
# Best-effort cleanup during shutdown.
207209
pass
208210
db.close()
209211

src/mcp_server_python_docs/services/package_docs.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@
3434

3535

3636
class _HTTPResponse(Protocol):
37-
def read(self, size: int = -1) -> bytes: ...
38-
def __enter__(self) -> "_HTTPResponse": ...
39-
def __exit__(self, exc_type: object, exc: object, tb: object) -> bool | None: ...
37+
def read(self, size: int = -1) -> bytes:
38+
raise NotImplementedError
39+
40+
def __enter__(self) -> "_HTTPResponse":
41+
raise NotImplementedError
42+
43+
def __exit__(self, exc_type: object, exc: object, tb: object) -> bool | None:
44+
raise NotImplementedError
4045

4146

4247
Fetcher = Callable[[str, float], _HTTPResponse]

tests/test_package_docs.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ def fetch(url: str, timeout: float):
5959
"project_urls": {"Community mirror": "https://mirror.example/demo"}}})
6060

6161
result = PackageDocsService(fetcher=fetch).lookup("demo")
62-
urls = [s.url for s in result.sources]
63-
assert "https://demo.example/" in urls
64-
assert "https://random-blog.example/demo" not in urls
65-
assert "https://mirror.example/demo" not in urls
62+
urls = {s.url for s in result.sources}
63+
assert urls == {"https://pypi.org/project/demo/", "https://demo.example/"}
6664
assert "community mirror" in (result.note or "").lower()
6765

6866

tests/test_stdio_smoke.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def read_stream(stream, sink: list[bytes]) -> None:
250250
try:
251251
proc.stdin.close()
252252
except BrokenPipeError:
253+
# The subprocess may have already closed stdin after handling the requests.
253254
pass
254255
proc.stdin = None
255256

0 commit comments

Comments
 (0)