Skip to content

Fix in_jupyter() detection for IPython shell subclasses - #919

Open
ncoop57 wants to merge 1 commit into
mainfrom
jupy-check
Open

Fix in_jupyter() detection for IPython shell subclasses#919
ncoop57 wants to merge 1 commit into
mainfrom
jupy-check

Conversation

@ncoop57

@ncoop57 ncoop57 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

in_jupyter() previously checked only the direct class name of the IPython shell for the string InteractiveShell. Environments that subclass ZMQInteractiveShell (e.g. CaptureShell, Google Colab, and other custom kernels) use class names that do not contain InteractiveShell, so in_jupyter() incorrectly returned False.

Change

Walk the MRO of the shell and return True if any ancestor class name contains InteractiveShell:

   return any("InteractiveShell" in c.__name__ for c in type(ipython_shell()).__mro__)

Impact

  • Correctly detects Jupyter in kernels that subclass the standard interactive shells
  • No behaviour change for standard Jupyter/IPython/terminal environments

@ncoop57 ncoop57 added the bug Something isn't working label Aug 24, 2026
@ncoop57
ncoop57 requested a review from jph00 August 24, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant