Skip to content

Commit a60979d

Browse files
fedorovclaude
andcommitted
ENH: stricter handling of empty comment lines in description parsers
Table description parser now stops collecting at an empty comment line (bare `#`), so only the actual description is captured. Column description parser raises ValueError if an empty comment line appears inside a `# description:` block, catching accidental paragraph breaks early. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c68d4ea commit a60979d

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

scripts/python/idc_index_data_manager.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@ def parse_table_description(sql_query: str) -> str:
6262
if desc_text:
6363
description_lines.append(desc_text)
6464
j += 1
65-
elif next_stripped.startswith("#"):
66-
# Empty comment line, skip
67-
j += 1
6865
else:
69-
# Non-comment line, stop collecting
66+
# Empty comment line or non-comment line, stop collecting
7067
break
7168
break
7269

@@ -116,9 +113,14 @@ def parse_column_descriptions(sql_query: str) -> dict[str, str]:
116113
if desc_text:
117114
description_lines.append(desc_text)
118115
i += 1
119-
elif next_stripped.startswith("#"):
120-
# Empty comment line, skip
121-
i += 1
116+
elif next_stripped == "#":
117+
msg = (
118+
"Empty comment line found inside a '# description:' block "
119+
f"at line {i + 1}. Column descriptions must not contain "
120+
"empty comment lines. Either remove the blank line or "
121+
"end the description before it."
122+
)
123+
raise ValueError(msg)
122124
else:
123125
# Non-comment line - this should contain the column definition
124126
break

tests/test_column_description_parser.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import pytest
34
from scripts.python.idc_index_data_manager import IDCIndexDataManager
45

56

@@ -163,7 +164,7 @@ def test_no_descriptions(self):
163164
assert len(descriptions) == 0
164165

165166
def test_empty_description_lines(self):
166-
"""Test handling of empty comment lines in descriptions."""
167+
"""Test that empty comment lines inside a description block raise an error."""
167168
sql_query = """
168169
SELECT
169170
# description:
@@ -173,12 +174,8 @@ def test_empty_description_lines(self):
173174
collection_name,
174175
FROM table
175176
"""
176-
descriptions = IDCIndexDataManager.parse_column_descriptions(sql_query)
177-
assert "collection_name" in descriptions
178-
# Empty comment lines should be skipped
179-
assert (
180-
descriptions["collection_name"] == "name of the collection additional info"
181-
)
177+
with pytest.raises(ValueError, match="Empty comment line found inside"):
178+
IDCIndexDataManager.parse_column_descriptions(sql_query)
182179

183180
def test_nested_array_select_with_if(self):
184181
"""Test parsing complex nested ARRAY/SELECT/IF statements."""

0 commit comments

Comments
 (0)