Skip to content

Commit

Permalink
Remove PythonSequentialLinter initialization from NotebookLinter init
Browse files Browse the repository at this point in the history
TODO #3544
  • Loading branch information
JCZuurmond committed Jan 17, 2025
1 parent 435f6c8 commit fd8f04d
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/databricks/labs/ucx/source_code/notebooks/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
Advice,
CurrentSessionState,
Failure,
Linter,
)

from databricks.labs.ucx.source_code.graph import (
Expand All @@ -35,7 +34,7 @@
UnresolvedPath,
)
from databricks.labs.ucx.source_code.notebooks.magic import MagicLine
from databricks.labs.ucx.source_code.python.python_ast import NodeBase, PythonSequentialLinter, Tree
from databricks.labs.ucx.source_code.python.python_ast import NodeBase, PythonLinter, Tree
from databricks.labs.ucx.source_code.notebooks.cells import (
CellLanguage,
Cell,
Expand Down Expand Up @@ -156,9 +155,6 @@ def __init__(
self._notebook: Notebook = notebook
self._inherited_tree = inherited_tree

# reuse Python linter across related files and notebook cells
# this is required in order to accumulate statements for improved inference
self._python_linter: PythonSequentialLinter = cast(PythonSequentialLinter, context.linter(Language.PYTHON))
self._python_trees: dict[PythonCell, Tree] = {} # the original trees to be linted

def lint(self) -> Iterable[Advice]:
Expand All @@ -167,13 +163,15 @@ def lint(self) -> Iterable[Advice]:
yield failure
return
for cell in self._notebook.cells:
if not self._context.is_supported(cell.language.language):
try:
linter = self._context.linter(cell.language.language)
except ValueError: # Language is not supported (yet)
continue
if isinstance(cell, PythonCell):
linter = cast(PythonLinter, linter)
tree = self._python_trees[cell]
advices = self._python_linter.lint_tree(tree)
advices = linter.lint_tree(tree)
else:
linter = self._linter(cell.language.language)
advices = linter.lint(cell.original_code)
for advice in advices:
yield dataclasses.replace(
Expand Down Expand Up @@ -311,11 +309,6 @@ def _load_source_from_path(self, path: Path | None) -> Notebook | None:
return None
return Notebook.parse(path, source, language)

def _linter(self, language: Language) -> Linter:
if language is Language.PYTHON:
return self._python_linter
return self._context.linter(language)

@staticmethod
def name() -> str:
return "notebook-linter"
Expand Down

0 comments on commit fd8f04d

Please sign in to comment.