Skip to content

Commit 23c6e4f

Browse files
committed
RDCIST-3853: Solve pyright issues
1 parent 0a4edab commit 23c6e4f

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

scripts/update_readme_snippets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ def update_readme_snippets(readme_path: Path = Path("README.md"), check_mode: bo
128128
)
129129
return False
130130
else:
131-
print(f" {readme_path} code snippets are up to date")
131+
print(f"[OK] {readme_path} code snippets are up to date")
132132
return True
133133
else:
134134
if updated_content != original_content:
135135
readme_path.write_text(updated_content)
136-
print(f" Updated {readme_path}")
136+
print(f"[OK] Updated {readme_path}")
137137
else:
138-
print(f" {readme_path} already up to date")
138+
print(f"[OK] {readme_path} already up to date")
139139
return True
140140

141141

src/mcp/os/posix/utilities.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ async def terminate_posix_process_tree(process: Process, timeout_seconds: float
2929
return
3030

3131
try:
32-
pgid = os.getpgid(pid)
33-
os.killpg(pgid, signal.SIGTERM)
32+
pgid = os.getpgid(pid) # type: ignore[attr-defined]
33+
os.killpg(pgid, signal.SIGTERM) # type: ignore[attr-defined]
3434

3535
with anyio.move_on_after(timeout_seconds):
3636
while True:
3737
try:
3838
# Check if process group still exists (signal 0 = check only)
39-
os.killpg(pgid, 0)
39+
os.killpg(pgid, 0) # type: ignore[attr-defined]
4040
await anyio.sleep(0.1)
4141
except ProcessLookupError:
4242
return
4343

4444
try:
45-
os.killpg(pgid, signal.SIGKILL)
45+
os.killpg(pgid, signal.SIGKILL) # type: ignore[attr-defined]
4646
except ProcessLookupError:
4747
pass
4848

src/mcp/os/win32/utilities.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
# Windows-specific imports for Job Objects
2121
if sys.platform == "win32":
22-
import pywintypes
2322
import win32api
2423
import win32con
2524
import win32job
@@ -28,7 +27,6 @@
2827
win32api = None
2928
win32con = None
3029
win32job = None
31-
pywintypes = None
3230

3331
JobHandle = int
3432

@@ -127,6 +125,11 @@ def pid(self) -> int:
127125
"""Return the process ID."""
128126
return self.popen.pid
129127

128+
@property
129+
def returncode(self) -> int | None:
130+
"""Return the process exit code (None if still running)."""
131+
return self.popen.returncode
132+
130133

131134
# ------------------------
132135
# Updated function
@@ -238,11 +241,17 @@ def _create_job_object() -> int | None:
238241
return None
239242

240243
try:
241-
job = win32job.CreateJobObject(None, "")
242-
extended_info = win32job.QueryInformationJobObject(job, win32job.JobObjectExtendedLimitInformation)
244+
job: JobHandle = win32job.CreateJobObject(None, "") # type: ignore[arg-type]
245+
extended_info = win32job.QueryInformationJobObject( # type: ignore[misc]
246+
job, win32job.JobObjectExtendedLimitInformation
247+
)
243248

244249
extended_info["BasicLimitInformation"]["LimitFlags"] |= win32job.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
245-
win32job.SetInformationJobObject(job, win32job.JobObjectExtendedLimitInformation, extended_info)
250+
win32job.SetInformationJobObject( # pyright: ignore[reportUnknownMemberType]
251+
job,
252+
win32job.JobObjectExtendedLimitInformation,
253+
extended_info, # pyright: ignore[reportUnknownArgumentType]
254+
)
246255
return job
247256
except Exception as e:
248257
logger.warning(f"Failed to create Job Object for process tree management: {e}")
@@ -269,7 +278,7 @@ def _maybe_assign_process_to_job(process: Process | FallbackProcess, job: JobHan
269278

270279
try:
271280
win32job.AssignProcessToJobObject(job, process_handle)
272-
process._job_object = job
281+
process._job_object = job # type: ignore[attr-defined]
273282
finally:
274283
win32api.CloseHandle(process_handle)
275284
except Exception as e:
@@ -295,7 +304,7 @@ async def terminate_windows_process_tree(process: Process | FallbackProcess, tim
295304
job = getattr(process, "_job_object", None)
296305
if job and win32job:
297306
try:
298-
win32job.TerminateJobObject(job, 1)
307+
win32job.TerminateJobObject(job, 1) # type: ignore[misc]
299308
except Exception:
300309
# Job might already be terminated
301310
pass

tests/issues/test_1027_win_unreachable_cleanup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ def echo(text: str) -> str:
213213
await anyio.sleep(0.1)
214214

215215
# Check if process is still running
216-
if hasattr(process, "returncode") and process.returncode is not None: # pragma: no cover
217-
pytest.fail(f"Server process exited with code {process.returncode}")
216+
# fmt: off
217+
if hasattr(process, "returncode") and process.returncode is not None: # pyright: ignore[reportUnknownMemberType,reportAttributeAccessIssue] # pragma: no cover
218+
pytest.fail(f"Server process exited with code {process.returncode}") # pyright: ignore[reportUnknownMemberType,reportAttributeAccessIssue]
219+
# fmt: on
218220

219221
assert Path(startup_marker).exists(), "Server startup marker not created"
220222

0 commit comments

Comments
 (0)