cajias/claude-skills/iterm2-mypy-workaround

Claude Code and agent skill by cajias/claude-skills

Trust tier 3
  • community
Source check pending

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-workaround

SKILL.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.7 package
  • mypy configured with strict = true
  • [[tool.mypy.overrides]] has module = ["iterm2.*"] with ignore_missing_imports = true
  • Error: Name "iterm2.Session" is not defined [name-defined]

Solution

Use this pattern (established in iterm-c4's discovery.py):

python
from __future__ import annotations
import iterm2 # noqa: TC002
# On function signatures using iterm2 types:
async def my_func(
session: iterm2.Session, # type: ignore[name-defined]
) -> None:
...

Key points:

  1. Import iterm2 at module level with # noqa: TC002 (suppresses ruff's

"move to TYPE_CHECKING" rule)

  1. Add # type: ignore[name-defined] on each line using iterm2 types in signatures
  2. Do NOT put import iterm2 inside if TYPE_CHECKING: — mypy still can't resolve it

Verification

  • uv run mypy iterm_c4/your_module.py passes with no errors
  • uv run ruff check iterm_c4/your_module.py passes (TC002 suppressed)

Notes

  • This pattern is used consistently across iterm-c4: discovery.py, monitor.py, session.py
  • The from __future__ import annotations is 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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/cajias/claude-skills/iterm2-mypy-workaround/badge)](https://verified-skill.com/skills/cajias/claude-skills/iterm2-mypy-workaround)

Something wrong with this skill or its page? Tell us.