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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Expose locals_max_depth and locals_overflow in traceback.install

## [14.2.0] - 2025-10-09

### Changed
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The following people have contributed to the development of Rich:
- [Logan Hunt](https://github.com/dosisod)
- [JP Hutchins](https://github.com/JPhutchins)
- [Ionite](https://github.com/ionite34)
- [Daniel Jäkel](https://github.com/kigstn)
- [Josh Karpel](https://github.com/JoshKarpel)
- [Jan Katins](https://github.com/jankatins)
- [Hugo van Kemenade](https://github.com/hugovk)
Expand Down
8 changes: 7 additions & 1 deletion rich/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .text import Text, TextType

if TYPE_CHECKING:
from .console import ConsoleRenderable
from .console import ConsoleRenderable, OverflowMethod


def render_scope(
Expand All @@ -19,6 +19,8 @@ def render_scope(
indent_guides: bool = False,
max_length: Optional[int] = None,
max_string: Optional[int] = None,
max_depth: Optional[int] = None,
overflow: Optional["OverflowMethod"] = None,
) -> "ConsoleRenderable":
"""Render python variables in a given scope.

Expand All @@ -30,6 +32,8 @@ def render_scope(
max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
Defaults to None.
max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to None.
max_depth (int, optional): Maximum depths of locals before truncating, or None to disable. Defaults to None.
overflow (OverflowMethod, optional): How to handle overflowing locals, or None to disable. Defaults to None.

Returns:
ConsoleRenderable: A renderable object.
Expand Down Expand Up @@ -57,6 +61,8 @@ def sort_items(item: Tuple[str, Any]) -> Tuple[bool, str]:
indent_guides=indent_guides,
max_length=max_length,
max_string=max_string,
max_depth=max_depth,
overflow=overflow,
),
)
return Panel.fit(
Expand Down
25 changes: 25 additions & 0 deletions rich/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
Console,
ConsoleOptions,
ConsoleRenderable,
OverflowMethod,
Group,
RenderResult,
group,
Expand Down Expand Up @@ -91,8 +92,10 @@ def install(
show_locals: bool = False,
locals_max_length: int = LOCALS_MAX_LENGTH,
locals_max_string: int = LOCALS_MAX_STRING,
locals_max_depth: Optional[int] = None,
locals_hide_dunder: bool = True,
locals_hide_sunder: Optional[bool] = None,
locals_overflow: Optional[OverflowMethod] = None,
indent_guides: bool = True,
suppress: Iterable[Union[str, ModuleType]] = (),
max_frames: int = 100,
Expand All @@ -114,8 +117,10 @@ def install(
locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
Defaults to 10.
locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
locals_max_depth (int, optional): Maximum depths of locals before truncating, or None to disable. Defaults to None.
locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.
locals_overflow (OverflowMethod, optional): How to handle overflowing locals, or None to disable. Defaults to None.
indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.
suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.

Expand Down Expand Up @@ -148,8 +153,10 @@ def excepthook(
show_locals=show_locals,
locals_max_length=locals_max_length,
locals_max_string=locals_max_string,
locals_max_depth=locals_max_depth,
locals_hide_dunder=locals_hide_dunder,
locals_hide_sunder=bool(locals_hide_sunder),
locals_overflow=locals_overflow,
indent_guides=indent_guides,
suppress=suppress,
max_frames=max_frames,
Expand Down Expand Up @@ -268,8 +275,10 @@ class Traceback:
locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
Defaults to 10.
locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
locals_max_depth (int, optional): Maximum depths of locals before truncating, or None to disable. Defaults to None.
locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.
locals_overflow (OverflowMethod, optional): How to handle overflowing locals, or None to disable. Defaults to None.
suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.
max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.

Expand All @@ -295,8 +304,10 @@ def __init__(
show_locals: bool = False,
locals_max_length: int = LOCALS_MAX_LENGTH,
locals_max_string: int = LOCALS_MAX_STRING,
locals_max_depth: Optional[int] = None,
locals_hide_dunder: bool = True,
locals_hide_sunder: bool = False,
locals_overlow: Optional[OverflowMethod] = None,
indent_guides: bool = True,
suppress: Iterable[Union[str, ModuleType]] = (),
max_frames: int = 100,
Expand All @@ -320,8 +331,10 @@ def __init__(
self.indent_guides = indent_guides
self.locals_max_length = locals_max_length
self.locals_max_string = locals_max_string
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.suppress: Sequence[str] = []
for suppress_entity in suppress:
Expand Down Expand Up @@ -351,8 +364,10 @@ def from_exception(
show_locals: bool = False,
locals_max_length: int = LOCALS_MAX_LENGTH,
locals_max_string: int = LOCALS_MAX_STRING,
locals_max_depth: Optional[int] = None,
locals_hide_dunder: bool = True,
locals_hide_sunder: bool = False,
locals_overflow: Optional[OverflowMethod] = None,
indent_guides: bool = True,
suppress: Iterable[Union[str, ModuleType]] = (),
max_frames: int = 100,
Expand All @@ -372,9 +387,11 @@ def from_exception(
indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.
locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
Defaults to 10.
locals_max_depth (int, optional): Maximum depths of locals before truncating, or None to disable. Defaults to None.
locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.
locals_overflow (OverflowMethod, optional): How to handle overflowing locals, or None to disable. Defaults to None.
suppress (Iterable[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.
max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.

Expand All @@ -388,6 +405,7 @@ def from_exception(
show_locals=show_locals,
locals_max_length=locals_max_length,
locals_max_string=locals_max_string,
locals_max_depth=locals_max_depth,
locals_hide_dunder=locals_hide_dunder,
locals_hide_sunder=locals_hide_sunder,
)
Expand All @@ -403,8 +421,10 @@ def from_exception(
indent_guides=indent_guides,
locals_max_length=locals_max_length,
locals_max_string=locals_max_string,
locals_max_depth=locals_max_depth,
locals_hide_dunder=locals_hide_dunder,
locals_hide_sunder=locals_hide_sunder,
locals_overlow=locals_overflow,
suppress=suppress,
max_frames=max_frames,
)
Expand All @@ -419,6 +439,7 @@ def extract(
show_locals: bool = False,
locals_max_length: int = LOCALS_MAX_LENGTH,
locals_max_string: int = LOCALS_MAX_STRING,
locals_max_depth: Optional[int] = None,
locals_hide_dunder: bool = True,
locals_hide_sunder: bool = False,
_visited_exceptions: Optional[Set[BaseException]] = None,
Expand All @@ -433,6 +454,7 @@ def extract(
locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
Defaults to 10.
locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
locals_max_depth (int, optional): Maximum depths of locals before truncating, or None to disable. Defaults to None.
locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.

Expand Down Expand Up @@ -560,6 +582,7 @@ def get_locals(
value,
max_length=locals_max_length,
max_string=locals_max_string,
max_depth=locals_max_depth,
)
for key, value in get_locals(frame_summary.f_locals.items())
if not (inspect.isfunction(value) or inspect.isclass(value))
Expand Down Expand Up @@ -754,6 +777,8 @@ def render_locals(frame: Frame) -> Iterable[ConsoleRenderable]:
indent_guides=self.indent_guides,
max_length=self.locals_max_length,
max_string=self.locals_max_string,
max_depth=self.locals_max_depth,
overflow=self.locals_overflow,
)

exclude_frames: Optional[range] = None
Expand Down