Skip to content

Update parser to have Notebook context #10264

@dhruvmanila

Description

@dhruvmanila

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    notebookRelated to (Jupyter) notebooksparserRelated to the parserwishNot on the current roadmap; maybe in the future

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions