Skip to content

fix: use sys.platform guards so mypy passes on Windows - #7401

Merged
Vidit-Ostwal merged 2 commits into
crewAIInc:mainfrom
modusensus:fix/windows-mypy-platform-compat
Sep 14, 2026
Merged

Vidit-Ostwal merged 2 commits into
crewAIInc:mainfrom
modusensus:fix/windows-mypy-platform-compat

Conversation

@modusensus

Copy link
Copy Markdown
Contributor

Fixes #7400

What

Two minimal changes so mypy passes under Windows platform semantics. Runtime behavior is unchanged.

  • lib/crewai/src/crewai/utilities/crew_chat.py: replace platform.system() == "Windows" with sys.platform == "win32", which mypy natively understands for branch pruning. The two # type: ignore[attr-defined] comments on the msvcrt calls were flagged as unused under win32 semantics and are removed. import platform was only used here and is dropped.
  • lib/crewai/src/crewai/memory/storage/lancedb_storage.py: wrap the existing try/except around resource in if sys.platform != "win32": so mypy skips it under win32 semantics. Runtime behavior is unchanged — the resource import already failed on Windows and was swallowed by the except.

Verification

  • uv run mypy lib/crewai/src/crewai/ on Windows: 8 errors → 0 (Success: no issues found in 515 source files)
  • uv run mypy --platform linux lib/crewai/src/crewai/: still clean (no regression)
  • uv run ruff check lib/: clean; pre-commit hooks pass
  • lib/crewai/tests/cli/test_crew_chat.py: 6 passed
  • memory/knowledge tests pass except pre-existing qdrant_edge DLL load failures on this Windows machine, which also occur on main and are unrelated to this change

This PR was drafted with AI assistance (Claude Code) and should receive the llm-generated label per CONTRIBUTING.md.

mypy does not narrow on `platform.system()`, so Windows-based contributors
get 8 spurious attr-defined/unused-ignore errors from the termios and
resource imports. Switch to `sys.platform` comparisons, which mypy
understands natively, and drop the now-unneeded type-ignore comments.

Fixes crewAIInc#7400
@coderabbitai

coderabbitai Bot commented Sep 12, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: fad22a71-4838-4a97-969f-dc97228cb263

📥 Commits

Reviewing files that changed from the base of the PR and between 894898f and ff74f0c.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/memory/storage/lancedb_storage.py
  • lib/crewai/src/crewai/utilities/crew_chat.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The PR updates platform checks in LanceDBStorage and flush_input. Resource-limit handling now skips Windows explicitly, and Windows input detection uses sys.platform. Unused imports and obsolete type-ignore comments are removed.

Changes

Windows platform checks

Layer / File(s) Summary
Platform-specific resource and input handling
lib/crewai/src/crewai/memory/storage/lancedb_storage.py, lib/crewai/src/crewai/utilities/crew_chat.py
LanceDBStorage skips resource operations on Windows. flush_input uses sys.platform == "win32" and removes obsolete type-ignore comments and the unused platform import.

Suggested reviewers: joaomdmoura

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to f847b

The changes are limited to platform-aware guards and type-checking cleanup, with no identified runtime risk remaining.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: using sys.platform guards to make mypy pass on Windows.
Description check ✅ Passed The description links issue #7400, explains the changes and rationale, and documents verification results. It uses a "What" section instead of the template's "Summary" heading and does not include a s…
Linked Issues check ✅ Passed Issue #7400 requires Windows-compatible mypy branch pruning without runtime changes. crew_chat.py now uses sys.platform == "win32", keeps msvcrt in the Windows branch, keeps termios in the non…
Out of Scope Changes check ✅ Passed The reviewed changes are limited to platform guards, related imports, type-ignore cleanup, and the associated exception comment in crew_chat.py and lancedb_storage.py. These changes directly imple…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Vidit-Ostwal Vidit-Ostwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Vidit-Ostwal
Vidit-Ostwal merged commit 7e80d94 into crewAIInc:main Sep 14, 2026
53 checks passed
@modusensus
modusensus deleted the fix/windows-mypy-platform-compat branch September 14, 2026 09:47
Mairaarshad19 pushed a commit to Mairaarshad19/crewAI that referenced this pull request Sep 16, 2026
mypy does not narrow on `platform.system()`, so Windows-based contributors
get 8 spurious attr-defined/unused-ignore errors from the termios and
resource imports. Switch to `sys.platform` comparisons, which mypy
understands natively, and drop the now-unneeded type-ignore comments.

Fixes crewAIInc#7400

Co-authored-by: Vidit Ostwal <110953813+Vidit-Ostwal@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mypy reports 8 attr-defined/unused-ignore errors on Windows from termios/resource imports

2 participants