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

Update parser to have Notebook context #10264

Open
dhruvmanila opened this issue Mar 7, 2024 · 1 comment
Open

Update parser to have Notebook context #10264

dhruvmanila opened this issue Mar 7, 2024 · 1 comment
Labels
notebook Related to (Jupyter) notebooks parser Related to the parser wish Not on the current roadmap; maybe in the future

Comments

@dhruvmanila
Copy link
Member

Taking the following 2 code cells as an example:

Cell 1:

def foo():
	print("first")

Cell 2:

	print("second")

Currently, Ruff would concatenate it into a single source and pass it to the parser. This means that the parser would see it as:

def foo():
	print("first")
	print("second")

Which is a valid code. But, actually the indentation before the second print statement is invalid as it is in another cell.

A possible solution, as suggested by @MichaReiser, would be to run the parser per cell, merge the statements, and update the node ranges for all the subsequent cells with the correct offset.

@dhruvmanila dhruvmanila added wish Not on the current roadmap; maybe in the future parser Related to the parser notebook Related to (Jupyter) notebooks labels Mar 7, 2024
@dhruvmanila
Copy link
Member Author

There might be more to it but it doesn't seem like the server raises any syntax errors. It could be that they strip any whitespace 🤷‍♂️

Screenshot 2024-03-07 at 10 59 43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notebook Related to (Jupyter) notebooks parser Related to the parser wish Not on the current roadmap; maybe in the future
Projects
None yet
Development

No branches or pull requests

1 participant