Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pr_body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
`_guess_lexer` uses `str.index()` to find the first newline in source code, but `index()` raises `ValueError` when the substring isn't found. The subsequent check `if new_line_index != -1` only makes sense with `str.find()`, which returns `-1` on miss.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be junk


When a traceback includes a frame from a single-line source file (no trailing newline), `_guess_lexer` crashes with an unhandled `ValueError` instead of rendering the traceback.

Changed `code.index("\n")``code.find("\n")` so the existing `-1` guard works as intended.
6 changes: 3 additions & 3 deletions rich/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def __init__(
locals_max_depth: Optional[int] = None,
locals_hide_dunder: bool = True,
locals_hide_sunder: bool = False,
locals_overlow: Optional[OverflowMethod] = None,
locals_overflow: Optional[OverflowMethod] = None,
indent_guides: bool = True,
suppress: Iterable[Union[str, ModuleType]] = (),
max_frames: int = 100,
Expand All @@ -334,7 +334,7 @@ def __init__(
self.locals_max_depth = locals_max_depth
self.locals_hide_dunder = locals_hide_dunder
self.locals_hide_sunder = locals_hide_sunder
self.locals_overflow = locals_overlow
self.locals_overflow = locals_overflow

self.suppress: Sequence[str] = []
for suppress_entity in suppress:
Expand Down Expand Up @@ -424,7 +424,7 @@ def from_exception(
locals_max_depth=locals_max_depth,
locals_hide_dunder=locals_hide_dunder,
locals_hide_sunder=locals_hide_sunder,
locals_overlow=locals_overflow,
locals_overflow=locals_overflow,
suppress=suppress,
max_frames=max_frames,
)
Expand Down