Skip to content

Re-expose supports_kitty_graphics as a lazy module attribute - #15461

Merged
Carreau merged 1 commit into
ipython:mainfrom
Madin-H23:fix/re-expose-supports-kitty-graphics
Nov 2, 2026
Merged

Carreau merged 1 commit into
ipython:mainfrom
Madin-H23:fix/re-expose-supports-kitty-graphics

Conversation

@Madin-H23

Copy link
Copy Markdown
Contributor

Fixes #15460

Problem

Commit b7a6320 (in #15424) replaced the import-time evaluation of supports_kitty_graphics with on-demand checks, which removed the name from the IPython.core.kitty module namespace. Downstream code that imports it - e.g. sagemath's sage/repl/interpreter.py - stopped working on 9.18.

Fix

Add a PEP 562 module-level __getattr__ to IPython.core.kitty that resolves supports_kitty_graphics on access by calling the existing private _supports_kitty_graphics():

>>> from IPython.core.kitty import supports_kitty_graphics  # works again

This keeps the startup-optimization intent of #15424 (no process-tree walk at import time) while restoring the public name; unknown attributes still raise AttributeError.

Tests

  • test_supports_kitty_graphics_public_alias - the attribute resolves on the module (red on main with AttributeError).
  • test_supports_kitty_graphics_from_import - from IPython.core.kitty import supports_kitty_graphics works (red on main with ImportError).
  • test_kitty_module_getattr_rejects_unknown_names - unknown attributes keep raising AttributeError.
  • Full tests/test_kitty.py: 25 passed, 1 skipped.

Note for CI: ruff check (latest) reports two pre-existing PLW1510 findings in tests/test_kitty.py (subprocess.run without explicit check=False, lines 50/266, untouched by this PR) and ruff format --check flags the pre-existing multi-line empty terminal_default_mime_renderers dict - all present on main, left untouched here.

🤖 This contribution was drafted with AI assistance; the analysis, the change and the tests are described above so that they can be reviewed.

Commit b7a6320 (ipython#15424) dropped the import-time evaluation of
supports_kitty_graphics to keep process-tree walks out of startup,
which removed the name from the module namespace; downstream code
such as sagemath still imports it.

Resolve it on access through a PEP 562 module __getattr__ instead:
`from IPython.core.kitty import supports_kitty_graphics` works again
while startup stays free of the detection cost.

Fixes ipython#15460

🤖 This contribution was drafted with AI assistance; the analysis, the change and the tests are described above so that they can be reviewed.
@Carreau Carreau added this to the 9.18 milestone Nov 1, 2026
@Carreau
Carreau merged commit 7b911de into ipython:main Nov 2, 2026
25 checks passed
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.

supports_kitty_graphics removed in 9.18

2 participants