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

Test: Notebook Inline Values after cell execution #238911

Closed
2 tasks done
Yoyokrazy opened this issue Jan 28, 2025 · 2 comments
Closed
2 tasks done

Test: Notebook Inline Values after cell execution #238911

Yoyokrazy opened this issue Jan 28, 2025 · 2 comments

Comments

@Yoyokrazy
Copy link
Contributor

Yoyokrazy commented Jan 28, 2025

Refs: #237263

Complexity: 4

author: @Yoyokrazy

Create Issue


Summary

Support for inline values has been added for notebooks, using the setting notebook.inlineValues. When enabled, after a cell is executed, inline values will be displayed after the line, according to either any registered InlineValueProvider or the default fallback which simply does regex matching against the variables stored in the kernel after that execution. The latter may

Steps to Test:

Part 1:

  • Enable the setting notebook.inlineValues
  • Execute a cell, ensuring that inline values are presented similar to how they would be during the debugging process, with different styling.
    • when running more complex cells, it is expected that these values can and will be incorrect. This is due to the values all being retrieved from the kernel state after the cell has been executed. Local functions will have clearly incorrect values, as they are just matched via regex according to the variable name, without any concept of scope.

Part 2:

  • Create an extension that contributes an inline value provider. A very simple example can be found here: https://github.com/Yoyokrazy/clean-nb-imports-ext/blob/inline-tpi/src/extension.ts
  • More advanced examples can perform more effective symbol matching, ignore python keywords, avoid local functions, etc. Values can be retrieved from the kernel using inline variable lookups, or statically determined and returned as inline variable text. Be sure to test both.

An example of a more complex cell, and the difference between the standard regex fallback vs the pylance provider:

pylance provider
Image

fallback (regex matching)
Image

cell content

a = {'value': 5}

b = 'world'

c = 10

def local_fn():
    a = 5
    b = 100

    c = a + b

    return c


result = local_fn()

a['pie'] = 3.14

test = 'hello'

print(a)

local_fn()

Known Issues

  • the fallback regex matching will often show more incorrect values than correct ones, leading to visual fatigue and overall not much useful info (lower in the cell will be more useful): Improve notebook inline value fallback #238912
  • inline values for dataframes can stretch past the viewport
  • dataframes can render with broken LF characeters (\n), and render with an excessive amount of whitespace

Thanks for testing!

@lszomoru
Copy link
Member

Local functions will have clearly incorrect values, as they are just matched via regex according to the variable name, without any concept of scope.

While I am not a notebook user this statement caught my eyes. I think that, in general we should never show content that we know, or have high confidence that it may be incorrect due to known limitations. If we render any inline values we should do so when we have high confidence that the value is correct.

@meganrogge
Copy link
Contributor

Works well and is useful! We should work on making this accessible for screen reader users.

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

No branches or pull requests

3 participants