Skip to content

Keep kitty graphics platform check reachable for mypy on win32 - #15419

Closed
cristianchiriac wants to merge 3 commits into
ipython:mainfrom
cristianchiriac:fix/kitty-mypy-unreachable
Closed

cristianchiriac wants to merge 3 commits into
ipython:mainfrom
cristianchiriac:fix/kitty-mypy-unreachable

Conversation

@cristianchiriac

Copy link
Copy Markdown
Contributor

The Run MyPy workflow currently fails on every new PR (e.g. #15414, #15416, #15417), on both the ubuntu job (in the --platform win32 step) and the windows job:

IPython/core/kitty.py:114: error: Statement is unreachable  [unreachable]

With mypy 2.4, if sys.platform not in ("darwin", "linux"): return False in _supports_kitty_graphics() is evaluated against the target platform. Under --platform win32 the early return is always taken, so everything after it is reported as unreachable (warn_unreachable = true). A # type: ignore[unreachable] wouldn't help, because warn_unused_ignores = true would then fail on linux/darwin.

This change compares a local copy of sys.platform, so mypy treats it as an ordinary runtime check on all platforms. Behavior is unchanged, and tests that monkeypatch sys.platform still work because the value is read on each call.

Testing (mypy 2.4.0, project config):

  • mypy IPython and mypy --platform linux|darwin|win32 IPython all report "no issues found". Before the change, --platform win32 reported the error above.
  • pytest tests/test_kitty.py: 18 passed, 1 skipped.

mypy 2.4 evaluates "sys.platform not in (...)" against the target platform.
With --platform win32 it treats the early return in _supports_kitty_graphics
as always taken and reports the rest of the function as unreachable, which
fails the "Run MyPy" workflow (warn_unreachable is enabled) on every PR.
Compare a local copy of sys.platform so the check stays a runtime check.
@cristianchiriac

Copy link
Copy Markdown
Contributor Author

Note: the remaining red check here, test (ubuntu-latest, 3.13) in Run Downstream tests, is the existing ipykernel collection error (Unknown config option: timeout), which also fails on main and is fixed separately in #15418. The Run MyPy jobs now pass on this PR.

@1MLightyears

Copy link
Copy Markdown
Contributor

Hi, my PR is also working on kitty.py ( #15424 ).
Hope to get pinged when this PR is merged, as I'm facing a similar issue.

@cristianchiriac

Copy link
Copy Markdown
Contributor Author

Merged main into this branch. The earlier test failure ('timeout' not found in markers while collecting tests/test_matplotlib_eventloops.py) came from that test file, which no longer exists on main. The mypy job on main currently fails on the same kitty.py:114 unreachable statement this PR fixes.

@cristianchiriac

Copy link
Copy Markdown
Contributor Author

The two remaining red jobs are Run Downstream tests (ipykernel's suite: 'timeout' not found in markers), which also fails on main. #15418 fixes that workflow by installing ipykernel's test dependency group. The regular test and mypy jobs pass.

@Carreau

Carreau commented Oct 22, 2026

Copy link
Copy Markdown
Member

This has been fixed in a different way, but thanks for this PR. Closing for now.

@Carreau Carreau closed this Oct 22, 2026
@Carreau Carreau added this to the no action milestone Oct 22, 2026
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.

4 participants