cajias/claude-skills/iterm2-mypy-workaround
Claude Code and agent skill by cajias/claude-skills
- community
Checking that the SKILL.md file is still in the repository.
Fix mypy "Name iterm2.Session is not defined" or "Name iterm2.Window is not defined" errors in iterm-c4 project. Use when: (1) mypy fails with name-defined errors on iterm2 types despite ignore_missing_imports=true in pyproject.toml, (2) working with the iTerm2 Python API in type-annotated code. The iterm2 package lacks proper type stubs, requiring a specific import + type-ignore pattern.
Install
npx vskill@latest install cajias/claude-skills/iterm2-mypy-workaroundSKILL.md
The same SKILL.md was published earlier as cajias/claude-skills/iterm2-mypy-workaround.
iterm2 Package mypy Type Resolution
Problem
The iterm2 Python package doesn't ship proper type stubs. Even with ignore_missing_imports = true configured for iterm2.* in mypy settings, using iterm2.Session, iterm2.Window, iterm2.App etc. in type annotations causes error: Name "iterm2.X" is not defined [name-defined].
Context / Trigger Conditions
- Project uses
iterm2>=2.7package - mypy configured with
strict = true [[tool.mypy.overrides]]hasmodule = ["iterm2.*"]withignore_missing_imports = true- Error:
Name "iterm2.Session" is not defined [name-defined]
Solution
Use this pattern (established in iterm-c4's discovery.py):
Key points:
- Import
iterm2at module level with# noqa: TC002(suppresses ruff's
"move to TYPE_CHECKING" rule)
- Add
# type: ignore[name-defined]on each line using iterm2 types in signatures - Do NOT put
import iterm2insideif TYPE_CHECKING:— mypy still can't resolve it
Verification
uv run mypy iterm_c4/your_module.pypasses with no errorsuv run ruff check iterm_c4/your_module.pypasses (TC002 suppressed)
Notes
- This pattern is used consistently across iterm-c4: discovery.py, monitor.py, session.py
- The
from __future__ import annotationsis required for all other TYPE_CHECKING imports
to work (ClaudeSession, PermissionPrompt, etc.)
- Ruff's TC003 rule (move stdlib imports to TYPE_CHECKING) works fine for collections.abc
imports but NOT for iterm2
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/iterm2-mypy-workaround/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/cajias/claude-skills/iterm2-mypy-workaround)