-
Notifications
You must be signed in to change notification settings - Fork 102
Do not type-check non-python cells in Jupyter Notebooks #1282
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -573,6 +573,15 @@ export class SourceFile { | |||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| //TODO: this isnt ideal because it re-reads the file for each cell which is unnecessary | ||||||||||||||||||||||||||||||||||||||||||||||
| source = getIPythonCells(this.fileSystem, this.getRealUri(), this._console)?.[cellIndex]?.source; | ||||||||||||||||||||||||||||||||||||||||||||||
| // Make sure we don't return any non-python cells | ||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||
| source && | ||||||||||||||||||||||||||||||||||||||||||||||
| ['%sql', '%%sql', '%sh', '%pip', '%run', '%fs', '%load', '%matplotlib', '%who', '%env'].includes( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this only checks the first line of the file. is basedpyright/packages/pyright-internal/src/parser/tokenizer.ts Lines 1240 to 1261 in 8b0f262
is there a way i can run databricks notebooks locally so i can mess around with it myself to learn how they work? it looks like i have to make an account and run it on their site or something?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. %sql is valid on the first line of a cell, and this method is called per cell so I think it's ok. Also the test I added is in the 3rd cell. There is no way of detecting databricks notebooks easily, you can also author them with vs code and it will work just fine. It's really just a jupyter notebook where you see %sql in the first cell. So I do not think we can distinguish between Databricks / Non-Databricks
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm also a bit skeptical about this change because it prevents errors from correctly appearing for users that are just working with regular notebooks. we still want to report an error for this invalid syntax on regular notebooks. i think if we do this we need a new setting called
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a more generic setting allowing to skip cells based on magic would be good |
||||||||||||||||||||||||||||||||||||||||||||||
| source[0].split(/[\s]/)[0] | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return ''; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| this._console.error(e instanceof Error ? e.message : String(e)); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this is the correct spot for this because this method is only called when running basedpyright from the CLI. when using the language server, the file contents get passed to the
SourceFileobject by writing tothis._writableData.clientDocumentContentsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, is there a method or so where this filtering would make sense? How do I test the language server?