Skip to content

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

Open
cristianchiriac wants to merge 1 commit into
ipython:mainfrom
cristianchiriac:fix/kitty-mypy-unreachable
Open

cristianchiriac wants to merge 1 commit into
ipython:mainfrom
cristianchiriac:fix/kitty-mypy-unreachable

Conversation

@cristianchiriac

Copy link
Copy Markdown

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

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.

This branch has not been deployed

No deployments
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.

2 participants