-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Inside of a notebook, magic cells should not cause an error in pylance #17058
Comments
I assume this would be blocked by "real" notebook cell support over the LSP, since we don't want to allow this in regular Python code (or maybe we special case the vscode-notebook schema sent for the fake concat docs). Right now, we aren't notebook aware at all (and don't know how to parse these). |
Well actually we want them in regular python code if using the interactive window too (but that seems less important). I was hoping we could just special case these somehow. Either in the concatenation layer or in pylance itself based on some way of detecting notebook cells. |
Without having to go full blown notebook in the LSP |
This is silly, but one way to hack it would be to replace every line that starts with |
Or, replace |
Unless the line is a continuation of the |
Well ideally autocomplete would work. |
Not having a syntax error is one thing, trying to autocomplete them is another. Does the notebook code already discard the syntax error or was that the main thing you were looking for? |
No it doesn't discard the syntax error at the moment. The red squiggle comes up. I agree the first step would be to not generate the squiggle. Second step is autocomplete. |
Here's another example of something similar: Maybe there's something we can do for notebooks to remove diagnostics that are not relevant for a cell. I was thinking do the removal at the concat level (as it knows about notebooks). Similar to what @jakebailey suggested above about adding extra spaces |
Wild, I didn't know |
I haven't found an easy reference, but if you read the docs here it ends up listing all the goofy things you can do with jupyter: Well at least in an ipython kernel. |
Wow, that's a lot. 🙁 |
Apparently in regular python files you do something like
You get the magic executed and avoid the linting errors. Related: microsoft/vscode-jupyter#3263 |
I think we were going to handle these in the python extension (where we parse the diagnostics as they come back) and skip ones for magics. |
I wanted to try and make the case that this issue should be treated more like a bug. I see how this can be considered an enhancement (it is a new scenario which was not considered initially), but for a jupyter notebook beginner like myself, a red squiggle in a notebook indicates that I did something wrong, and a squiggle on the first character of a notebook indicates that perhaps I have a setup issue. Despite the error, the cell actually executed without a problem. IMHO, in general, it is problematic if a tool reports a squiggle and I have no possibility to get rid of it; this erodes my trust in the tool. This can also be frustrating for users who want to have a clean Problems panel. |
If this issue can be fixed, it would be awesome to include awareness of imports and functions in |
FWIW my suggestion here is to not ignore the diagnostic, but to replace the magic lines with an equivalent number of spaces when doing the translation, if possible. I'm not sure how exactly the cells are merged, so maybe that's not hard, but that would prevent follow-on errors that depend on how we recover from the invalid syntax that these magic lines have. |
Happy to read that this issue is being addressed - the wiggles are really annoying. As far as I understand, ipykernel adds three syntax additions that are relevant and should be addressed here.
Sometimes, ipykernel also expands variables, ie. it replaces variable tokens like $my_var with corresponding variable values defined outside of the cell. However, Python cells seem not to do this variable expansion, hence can likely be neglected in this case. |
A potential workaround found in this StackOverflow answer is to use For example:
|
Moving to python since the fix will be there. I can now add a news entry |
Add a cell like so:
That is a valid magic command. It would be nice if Pylance would recognize these.
The text was updated successfully, but these errors were encountered: