Skip to content

Commit 2d4a4ea

Browse files
committed
Remove dead branches after proven that they cannot be reached.
1 parent 02e10bb commit 2d4a4ea

File tree

1 file changed

+38
-55
lines changed

1 file changed

+38
-55
lines changed

tracerite/trace.py

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -167,51 +167,44 @@ def _extract_emphasis_columns(
167167
if not (end_line and start_col is not None and end_col is not None):
168168
return None
169169

170-
try:
171-
all_lines = lines.splitlines(keepends=True)
172-
segment_start = error_line_in_context - 1 # Convert to 0-based for indexing
173-
segment_end = end_line if end_line else error_line_in_context
174-
175-
if not (0 <= segment_start < len(all_lines) and segment_end <= len(all_lines)):
176-
return None
177-
178-
# Extract the segment using CPython's approach
179-
relevant_lines = all_lines[segment_start:segment_end]
180-
segment = "".join(relevant_lines)
181-
182-
# Trim segment using start_col and end_col
183-
segment = segment[
184-
start_col : len(segment) - (len(relevant_lines[-1]) - end_col)
185-
]
186-
# Attempt to parse for anchors
187-
anchors = None
188-
with suppress(Exception):
189-
anchors = trace_cpy._extract_caret_anchors_from_line_segment(segment)
190-
if not anchors:
191-
return None
192-
193-
l0, l1, c0, c1 = (
194-
anchors.left_end_lineno,
195-
anchors.right_start_lineno,
196-
anchors.left_end_offset,
197-
anchors.right_start_offset,
198-
)
199-
# We get 0-based line numbers and offsets within the segment,
200-
# so we need to adjust them to match the original code.
201-
if l0 == 0:
202-
c0 += start_col
203-
if l1 == 0:
204-
c1 += start_col
205-
206-
# Convert to 1-based inclusive line numbers for consistency
207-
lfirst = l0 + segment_start + 1
208-
lfinal = l1 + segment_start + 1
209-
210-
return Range(lfirst, lfinal, c0, c1)
211-
except Exception:
212-
logger.exception("Error extracting caret anchors")
170+
all_lines = lines.splitlines(keepends=True)
171+
segment_start = error_line_in_context - 1 # Convert to 0-based for indexing
172+
segment_end = end_line if end_line else error_line_in_context
213173

214-
return None
174+
if not (0 <= segment_start < len(all_lines) and segment_end <= len(all_lines)):
175+
return None
176+
177+
# Extract the segment using CPython's approach
178+
relevant_lines = all_lines[segment_start:segment_end]
179+
segment = "".join(relevant_lines)
180+
181+
# Trim segment using start_col and end_col
182+
segment = segment[start_col : len(segment) - (len(relevant_lines[-1]) - end_col)]
183+
# Attempt to parse for anchors
184+
anchors = None
185+
with suppress(Exception):
186+
anchors = trace_cpy._extract_caret_anchors_from_line_segment(segment)
187+
if not anchors:
188+
return None
189+
190+
l0, l1, c0, c1 = (
191+
anchors.left_end_lineno,
192+
anchors.right_start_lineno,
193+
anchors.left_end_offset,
194+
anchors.right_start_offset,
195+
)
196+
# We get 0-based line numbers and offsets within the segment,
197+
# so we need to adjust them to match the original code.
198+
if l0 == 0:
199+
c0 += start_col
200+
if l1 == 0:
201+
c1 += start_col
202+
203+
# Convert to 1-based inclusive line numbers for consistency
204+
lfirst = l0 + segment_start + 1
205+
lfinal = l1 + segment_start + 1
206+
207+
return Range(lfirst, lfinal, c0, c1)
215208

216209

217210
def _build_position_map(raw_tb):
@@ -404,9 +397,6 @@ def _parse_line_to_fragments_unified(
404397
line, common_indent_len, mark_positions, em_positions, line_char_offset
405398
):
406399
"""Parse a single line into fragments using unified highlighting."""
407-
if not line:
408-
return []
409-
410400
line_content, line_ending = _split_line_content(line)
411401
if not line_content and not line_ending:
412402
return []
@@ -438,8 +428,7 @@ def _parse_line_to_fragments_unified(
438428
comment_trailing = comment_part[len(comment_trimmed) :]
439429

440430
comment_with_leading_space = code_whitespace + comment_trimmed
441-
if comment_with_leading_space:
442-
fragments.append({"code": comment_with_leading_space, "comment": "solo"})
431+
fragments.append({"code": comment_with_leading_space, "comment": "solo"})
443432

444433
# Add trailing content
445434
trailing_content = comment_trailing + line_ending
@@ -500,9 +489,6 @@ def _parse_lines_to_fragments(lines_text, mark_range=None, em_range=None):
500489
Returns:
501490
List of line dictionaries with fragment information
502491
"""
503-
if not lines_text:
504-
return []
505-
506492
lines = lines_text.splitlines(keepends=True)
507493
if not lines:
508494
return []
@@ -640,9 +626,6 @@ def _create_fragments_with_highlighting(text, mark_positions, em_positions):
640626
break
641627

642628
fragment_text = text[start:end]
643-
if not fragment_text:
644-
continue
645-
646629
fragment = {"code": fragment_text}
647630

648631
# Determine mark status

0 commit comments

Comments
 (0)