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

Handle execute_request_impl(user_expressions = ) #40

Open
romainfrancois opened this issue Nov 14, 2023 · 1 comment
Open

Handle execute_request_impl(user_expressions = ) #40

romainfrancois opened this issue Nov 14, 2023 · 1 comment

Comments

@romainfrancois
Copy link
Contributor

romainfrancois commented Nov 14, 2023

Not sure what user_expressions = is

@adamblake
Copy link

I did a little research on this, and hope it helps you out!

In my understanding they are lightweight expressions that are run after the main request code is executed. They are run against the state of the user's kernel, but they shouldn't affect the state of the kernel. An example would be something like a front-end tool that requests the value of a variable after it is assigned so that it can be inspected:

Request:

{
  "code": "x = 10",
  "silent": false,
  "store_history": true,
  "user_expressions": {
    "inspect_x": "x"
  }
}

Reply:

{
  "header": {
    "msg_type": "execute_reply",
    ...
  },
  "parent_header": ...,
  "metadata": {},
  "content": {
    "status": "ok",
    "execution_count": 1,
    "payload": [],
    "user_expressions": {
      "inspect_x": {
        "status": "ok",
        "data": {
          "text/plain": "10"
        },
        "metadata": {}
      }
    }
  }
}

A use-case I found is in MyST Inline Expressions. They have an open PR for this here in IRKernel that hasn't been touched in a few months: IRkernel/IRkernel#742

The Jupyter Client documentation also gives another use-case of a front-end requesting data to get information for prompts. I found it a little confusing, but here it is:

The user_expressions field deserves a detailed explanation. In the past, IPython had the notion of a prompt string that allowed arbitrary code to be evaluated, and this was put to good use by many in creating prompts that displayed system status, path information, and even more esoteric uses like remote instrument status acquired over the network. But now that IPython has a clean separation between the kernel and the clients, the kernel has no prompt knowledge; prompts are a frontend feature, and it should be even possible for different frontends to display different prompts while interacting with the same kernel. user_expressions can be used to retrieve this information.

Any error in evaluating any expression in user_expressions will result in only that key containing a standard error message, of the form:

{
    'status' : 'error',
    'ename' : 'NameError',
    'evalue' : 'foo',
    'traceback' : ...
}

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

No branches or pull requests

2 participants