-
Notifications
You must be signed in to change notification settings - Fork 33
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
Support for Jupyter Notebook #173
Comments
looks like the jupyter extension is separate from pylance and also open source: https://github.com/microsoft/vscode-jupyter does that cover it? or is there some pylance-specific functionality that we need to add? |
When pylance is enabled, code inside notebooks have highlights & intelligence but basedpyright no. i think this part was supported by pylance (closed source XD). |
ah ok, in that case this might be easier than i thought. will look into it when i have time |
Is this relevant? microsoft/vscode-python#23897 EDIT: It's in pre-release and Jedi now works in each individual cell. |
i think that's only relevant to language servers that use the |
Has anyone figured out a workaround to used |
I took a tour through some of the linked issues to try to piece together your attempts to address this. Is this the next step?
Sounds like you have a sort of concrete idea the direction you want to take this? Want to add back the help-wanted label? It does seem like a good independent feature (to answer this question you posed)
Yes, I would! My use case would be tests, authored as notebooks (because that expands the author pool), for a collection of python packages in a mono repo. |
I see, Does using nbQA feel like a nice path forward? Looks like that's how ruff does it. https://nbqa.readthedocs.io/en/latest/tutorial.html#writing-your-own-tool edit: this seems to work out of the box: uv run nbqa basedpyright <mynotebook>.ipynb |
i've just deleted the "help wanted" label from this project, since i find it quite misleading. it implies that issues without this label are not open for contributors to work on, which isn't true. i welcome contributors on any currently open issue regardless of whether it has the label.
are you sure? it's probably just treating the json conents of the file as python and type checking that instead. for example i tried it on the following notebook: and received these nonsense errors:
because it sees the json contents of the {
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"foo: int = \"\""
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
} ideally it should fail on filetypes it doesn't recognize. see #90 |
Yes! You're correct, running However, this specific tool - nbQA - appears to be transforming the input stream by concatenating the code cells into a single python "file". And so, I do get type checking output, though the "line numbers" are of course synthetic. Note again the precise command to run: uv run nbqa basedpyright <mynotebook>.ipynb Presumably this works because you've setup It also seems to support formatting tools, so they must have some kind of way (not sure how sophisticated) of taking the transformed python "file" and mapping that back into the code snippets for each notebook cell. This doesn't get us all the way on its own (though it does, I think, help to run |
What I'm not sure is whether, conventionally, IDEs (and vscode is the one I care about) that want to run an LSP on code from a notebook do this handling themselves (the stitching and un-stitching) or pass the whole JSON. |
oops, i completely missed that you were running it with this separate nbqa tool i haven't looked into it much but i don't think it supports language servers. i'm thinking we probably need to just add support for it natively instead of relying on external tools. some of pylance's code for notebooks seems to have made its way back to pyright, some of it we may be able to build on top of |
Is it perhaps just the vscode extension config? Spit balling here: https://github.com/DetachHead/basedpyright/blob/main/packages/vscode-pyright/src/extension.ts#L182 It's setup with
which can be a and I think it's only doing So I wonder what will happen if we just add That might not be able to handle the stitching of code across cells, so you'd probably wind up with lots of undeclared symbols. But maybe some extra metadata is passed along. |
Ha... yeah that actually works! As expected, cross-cell references do not work. But even with treating each cell as an independent snippet, I get squigglies, and that's not nothing! Worth opening an PR for this narrow thing? |
sure go ahead! let me know if you get stuck on anything and i will try to help out |
That would be a huge step, I love Is below possible?
|
Same issue here. Did you managed to get it working? |
turns out most of the code required to support notebooks was already in pyright. i got it working today in #1035 i just need to add support for them in the CLI, which i hope to get done this week. i know this is the most upvoted issue by far so i appreciate everybody's patience |
that should be working. do you happen to have an older version of basedpyright installed in your environment than the extension version? you'll have to update both for it to work properly |
My bad, working beautifully in jupyter notebooks now |
still missing now.
The text was updated successfully, but these errors were encountered: