Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send omit_sections to IPython to choose which sections of documentation you don't want #809

Merged
merged 3 commits into from
Nov 29, 2021

Conversation

fasiha
Copy link
Contributor

@fasiha fasiha commented Nov 27, 2021

This PR brings to ipykernel a recent IPython PR ipython/ipython#13343 which allows us to customize IPython's responses to info and inspect messages by specifying which documentation sections we don't want. For example, numpy.sin returns the following sections:

  • Call signature
  • Type
  • String form
  • File
  • Docstring
  • Class docstring

and with the new omit_sections keyword argument, we can for example specify that we are not interested in the File, String form, and Type sections, thereby saving runtime and bandwidth by not generating those documentation sections.

In this present PR, we enable ipykernel's inspect message to take advantage of omit_sections. If the client provides omit_sections in its request, we'll pass it on to IPython.

Nota bene if merged, this PR should be released with an ipykernel that depends on IPython 8.0, the milestone @Carreau has set in ipython/ipython#13343.


To test this using JupyterLab for example:

  1. install ipython master
  2. install this PR's branch of ipykernel (https://github.com/fasiha/ipykernel/tree/blocklist-for-inspector)
  3. install https://github.com/fasiha/jupyterlab/tree/use-omit_sections branch of jupyterlab and start it: this branch has configured its inspector to omit all sections except docstrings
  4. run the following in a notebook cell:
import numpy
numpy.sin
numpy.exp
  1. open JupyterLab's contextual help menu and click on "exp" and "sin", etc.

Original ipykernel:

Screen Shot 2021-11-26 at 7 19 14 PM

This PR with customized JupyterLab to omit numerous sections:

Screen Shot 2021-11-26 at 7 19 48 PM


Recommended triage: enhancement?

This leverages a recent pull request in IPython:

ipython/ipython#13343
@blink1073 blink1073 added this to the 6.5 milestone Nov 27, 2021
There are two options suggested in
ipython#809:

1. use TypeError to catch non-existent omit_sections kw. This will work with
master but will be less clear when we deprecate IPython 7.x in a few years.

2. use IPython version_info, which makes cleanup easier but means we won't be
able to use this feature with master IPython, only v8.

Going with ipython#2 because it's cleaner.
@blink1073
Copy link
Contributor

Thanks again @fasiha!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants