MCPcopy
hub / github.com/marimo-team/marimo / unwrap_cell_body

Function unwrap_cell_body

marimo/_ast/parse.py:87–106  ·  view source on GitHub ↗

Extract the body of a wrapped `def _():` cell after ruff formatting. Used by RuffFormatter to unwrap cells that were temporarily wrapped in a dummy function so ruff applies function-scope blank-line rules (E301) instead of file-scope rules (E302).

(formatted: str)

Source from the content-addressed store, hash-verified

85
86
87def unwrap_cell_body(formatted: str) -> str:
88 """Extract the body of a wrapped `def _():` cell after ruff formatting.
89
90 Used by RuffFormatter to unwrap cells that were temporarily wrapped in a
91 dummy function so ruff applies function-scope blank-line rules (E301)
92 instead of file-scope rules (E302).
93 """
94 tree = ast_parse(formatted)
95 fn = tree.body[0]
96 if not isinstance(fn, ast.FunctionDef):
97 raise ValueError(
98 f"Expected a FunctionDef node, got {type(fn).__name__}"
99 )
100 if fn.end_lineno is None:
101 raise ValueError("FunctionDef node has no end_lineno")
102 extractor = Extractor(formatted)
103 raw = extractor.extract_from_offsets(
104 fn.body[0].lineno - 1, 0, fn.end_lineno - 1, fn.end_col_offset
105 )
106 return fixed_dedent(raw).strip()
107
108
109def extract_lineno(node: Node) -> int:

Callers 1

formatMethod · 0.90

Calls 5

extract_from_offsetsMethod · 0.95
ast_parseFunction · 0.85
ExtractorClass · 0.85
fixed_dedentFunction · 0.85
stripMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…