Skip to content

Commit 036e19f

Browse files
committed
tidy: remove duplicate comments
1 parent 4bdb4c9 commit 036e19f

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

marimo/_ast/transformers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,11 @@ def __init__(self, import_name: str, keep_one: bool = False) -> None:
195195
self.keep_one = keep_one
196196
self.import_name = import_name
197197

198-
def _return_once(self, node: ast.Import | ast.ImportFrom, original_names:
199-
list[ast.alias]) -> Optional[ast.Import | ast.ImportFrom]:
198+
def _return_once(
199+
self,
200+
node: ast.Import | ast.ImportFrom,
201+
original_names: list[ast.alias],
202+
) -> Optional[ast.Import | ast.ImportFrom]:
200203
if node.names:
201204
return node
202205
elif self.keep_one:

marimo/_convert/comment_preserver.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ def wrapper(*args: object, **kwargs: object) -> list[str]:
7373
original_sources = args[0]
7474

7575
# Merge comments back into transformed sources
76-
result = self._merge_comments(original_sources, transformed_sources)
76+
result = self._merge_comments(
77+
original_sources, transformed_sources
78+
)
7779

7880
# Update our internal comment data to track only the clean transformed sources
7981
# This clears old comments that no longer apply
@@ -158,10 +160,14 @@ def _apply_comments_to_source(
158160

159161
if chosen_comment:
160162
comment_text = chosen_comment.text
161-
if chosen_comment.col > 0 and target_line_idx < len(original_lines):
163+
if chosen_comment.col > 0 and target_line_idx < len(
164+
original_lines
165+
):
162166
# Inline comment - append to the line if not already present
163167
current_line = result_lines[target_line_idx]
164-
if not current_line.rstrip().endswith(comment_text.rstrip()):
168+
if not current_line.rstrip().endswith(
169+
comment_text.rstrip()
170+
):
165171
result_lines[target_line_idx] = (
166172
current_line.rstrip() + " " + comment_text
167173
)
@@ -171,7 +177,9 @@ def _apply_comments_to_source(
171177

172178
return "\n".join(result_lines)
173179

174-
def _update_comments_for_transformed_sources(self, sources: list[str]) -> None:
180+
def _update_comments_for_transformed_sources(
181+
self, sources: list[str]
182+
) -> None:
175183
"""Update internal comment data to track the transformed sources."""
176184
self.sources = sources
177185
self.comments_by_source = {}

marimo/_convert/ipynb.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,14 @@ def transform_remove_duplicate_imports(sources: list[str]) -> list[str]:
659659
scoped = set()
660660
for var, instances in cell.variable_data.items():
661661
for instance in instances:
662-
if (var in imports or var in scoped) and instance.kind == "import":
662+
if (
663+
var in imports or var in scoped
664+
) and instance.kind == "import":
663665
# If it's not in global imports, we keep one instance
664666
keep_one = var not in imports
665-
transformer = RemoveImportTransformer(var, keep_one=keep_one)
667+
transformer = RemoveImportTransformer(
668+
var, keep_one=keep_one
669+
)
666670
source = transformer.strip_imports(source)
667671
scoped.add(var)
668672
imports.update(scoped)

0 commit comments

Comments
 (0)