Language metadata is not updated in .NET notebook
stewartadam opened this issue · comments
Describe the bug
Creating a Jupyter notebook in VS Code appears to default to Python, which produces Python language metadata in the notebook:
https://gist.github.com/stewartadam/528689d9bb917715a4c16a6ff9282de3
This metadata is not updated or removed when switching the notebook to .NET Interactive, which causes issues for tools like Ruff which try and parse Python code out of notebooks: astral-sh/ruff#12281
Asks:
- The notebook language should be updated to C# when the kernel is switched
- Polyglot metadata on cells should be removed when changing the kernel back to Python
Please complete the following:
Which version of .NET Interactive are you using? (In a notebook, run the #!about
magic command. ):
Version: 1.0.522904+cdfa48b2ea1a27dfe0f545c42a34fd3ec7119074
Library version: 1.0.0-beta.24229.4+cdfa48b2ea1a27dfe0f545c42a34fd3ec7119074
Build date: 2024-07-10T18:57:05.9093659Z
- OS
- Windows 11
- Windows 10
- macOS
- Linux (Please specify distro)
- iOS
- Android
- Browser
- Chrome
- Edge
- Firefox
- Safari
- Frontend
- Jupyter Notebook
- Jupyter Lab
- nteract
- Visual Studio Code
- Visual Studio Code Insiders
- Visual Studio
- Other (please specify)
Cell-level language is independent from which kernel is being used. Not all frontends will even look at this metadata. For example, .NET Interactive / Polyglot Notebooks metadata isn't read by JupyterLab, Jupyter Notebook, etc.
Cell-level language is independent from which kernel is being used
This part is expected - but the ask is to remove cell metadata the front-end created when switching kernels to avoid stale data. The current state makes it impossible for tools like Ruff to parse out which language a cell is, since both Python and .NET cell metadata are left hanging around.
Removing cell metadata would mean that the act of switching kernels even accidentally -- or, for example, because the .NET Interactive kernel isn't available on your machine -- would remove important information about which cells target which languages or subkernels.
Do you know why Ruff reads cell-level metadata that's meaningless to Jupyter?
It's parsing notebooks to apply linting rules.
This might be out of scope of the extension, but ideally there would be a canonical way to specify the cell's language that all frontends or tools could share while parsing the notebook.
Jupyter doesn't have the concept of cell-level language. Otherwise, .NET Interactive would have adopted it.