Skip to content

Commit

Permalink
Add type information to local labels
Browse files Browse the repository at this point in the history
  • Loading branch information
DubiousCactus committed Nov 3, 2024
1 parent b07b3b1 commit 2a56f34
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions bootstrap/tui/widgets/locals_panel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any, Dict
from typing import Any, Dict, List

import numpy as np
import torch
from textual.app import ComposeResult
from textual.containers import VerticalScroll
from textual.widgets import Collapsible, Pretty, Static
Expand All @@ -11,10 +13,17 @@ def compose(self) -> ComposeResult:

async def add_locals(self, locals: Dict[str, Any]) -> None:
for name, val in locals.items():
title = f"{name}: {type(val).__name__}"
if isinstance(val, torch.Tensor) or isinstance(val, np.ndarray):
title += f", {val.shape}"
elif isinstance(val, List):
title += f", {len(val)} elements"
elif isinstance(val, Dict):
title += f", {len(val)} keys"
await self.query_one("#locals").mount(
Collapsible(
Pretty(val),
title=name,
title=title,
)
)

Expand Down

0 comments on commit 2a56f34

Please sign in to comment.