← eval_submission

rich_3676

failed WRONG_FIX wrong_fix · 21 tool calls · 179 s · Textualize/rich

Task input

Notes

Add support for Exception.__notes__

Tool calls (22)

#ToolArgumentsResult
1run_command
{
 "command": "grep -rn \"traceback\" rich | head -20"
}
{"status": "ok", "stdout": "rich/default_styles.py:115: \"traceback.error\": Style(color=\"red\", italic=True),\nrich/default_styles.py:116: \"traceback.border.
full
{"status": "ok", "stdout": "rich/default_styles.py:115:    \"traceback.error\": Style(color=\"red\", italic=True),\nrich/default_styles.py:116:    \"traceback.border.syntax_error\": Style(color=\"bright_red\"),\nrich/default_styles.py:117:    \"traceback.border\": Style(color=\"red\"),\nrich/default_styles.py:118:    \"traceback.text\": Style.null(),\nrich/default_styles.py:119:    \"traceback.title\": Style(color=\"red\", bold=True),\nrich/default_styles.py:120:    \"traceback.exc_type\": Style(color=\"bright_red\", bold=True),\nrich/default_styles.py:121:    \"traceback.exc_value\": Style.null(),\nrich/default_styles.py:122:    \"traceback.offset\": Style(color=\"bright_red\", bold=True),\nrich/default_styles.py:123:    \"traceback.error_range\": Style(underline=True, bold=True, dim=False),\nrich/logging.py:15:from .traceback import Traceback\nrich/logging.py:37:        rich_tracebacks (bool, optional): Enable rich tracebacks with syntax highlighting and formatting. Defaults to False.\nrich/logging.py:38:        tracebacks_width (Optional[int], optional): Number of characters used to render tracebacks, or None for full width. Defaults to None.\nrich/logging.py:39:        tracebacks_code_width (int, optional): Number of code characters used to render tracebacks, or None for full width. Defaults to 88.\nrich/logging.py:40:        tracebacks_extra_lines (int, optional): Additional lines of code to render tracebacks, or None for full width. Defaults to None.\nrich/logging.py:41:        tracebacks_theme (str, optional): Override pygments theme used in traceback.\nrich/logging.py:42:        tracebacks_word_wrap (bool, optional): Enable word wrapping of long tracebacks lines. Defaults to True.\nrich/logging.py:43:        tracebacks_show_locals (bool, optional): Enable display of locals in tracebacks. Defaults to False.\nrich/logging.py:44:        tracebacks_suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.\nrich
2run_command
{
 "command": "find rich -name \"*traceback*\""
}
{"status": "ok", "stdout": "rich/traceback.py\n", "exit_code": 0}
full
{"status": "ok", "stdout": "rich/traceback.py\n", "exit_code": 0}
3read_file
{
 "filepath": "rich/traceback.py"
}
{"status": "ok", "filepath": "rich/traceback.py", "content": "import inspect\nimport linecache\nimport os\nimport sys\nfrom dataclasses import dataclass, field\
full
{"status": "ok", "filepath": "rich/traceback.py", "content": "import inspect\nimport linecache\nimport os\nimport sys\nfrom dataclasses import dataclass, field\nfrom itertools import islice\nfrom traceback import walk_tb\nfrom types import ModuleType, TracebackType\nfrom typing import (\n    Any,\n    Callable,\n    Dict,\n    Iterable,\n    List,\n    Optional,\n    Sequence,\n    Tuple,\n    Type,\n    Union,\n)\n\nfrom pygments.lexers import guess_lexer_for_filename\nfrom pygments.token import Comment, Keyword, Name, Number, Operator, String\nfrom pygments.token import Text as TextToken\nfrom pygments.token import Token\nfrom pygments.util import ClassNotFound\n\nfrom . import pretty\nfrom ._loop import loop_last\nfrom .columns import Columns\nfrom .console import Console, ConsoleOptions, ConsoleRenderable, RenderResult, group\nfrom .constrain import Constrain\nfrom .highlighter import RegexHighlighter, ReprHighlighter\nfrom .panel import Panel\nfrom .scope import render_scope\nfrom .style import Style\nfrom .syntax import Syntax\nfrom .text import Text\nfrom .theme import Theme\n\nWINDOWS = sys.platform == \"win32\"\n\nLOCALS_MAX_LENGTH = 10\nLOCALS_MAX_STRING = 80\n\n\ndef install(\n    *,\n    console: Optional[Console] = None,\n    width: Optional[int] = 100,\n    code_width: Optional[int] = 88,\n    extra_lines: int = 3,\n    theme: Optional[str] = None,\n    word_wrap: bool = False,\n    show_locals: bool = False,\n    locals_max_length: int = LOCALS_MAX_LENGTH,\n    locals_max_string: int = LOCALS_MAX_STRING,\n    locals_hide_dunder: bool = True,\n    locals_hide_sunder: Optional[bool] = None,\n    indent_guides: bool = True,\n    suppress: Iterable[Union[str, ModuleType]] = (),\n    max_frames: int = 100,\n) -> Callable[[Type[BaseException], BaseException, Optional[TracebackType]], Any]:\n    \"\"\"Install a rich traceback handler.\n\n    Once installed, any tracebacks will be printed with syntax highlighting and rich formatting.\n\n\n    Args:\n        c
4read_file
{
 "filepath": "rich/traceback.py",
 "start_line": 151,
 "end_line": 797
}
{"status": "ok", "filepath": "rich/traceback.py", "content": " tb = tb.tb_next\n\n excepthook(exc_tuple[0], exc_tuple[1], tb)\n tb_data = {} # clear data upon u
full
{"status": "ok", "filepath": "rich/traceback.py", "content": "                tb = tb.tb_next\n\n            excepthook(exc_tuple[0], exc_tuple[1], tb)\n            tb_data = {}  # clear data upon usage\n\n        # replace _showtraceback instead of showtraceback to allow ipython features such as debugging to work\n        # this is also what the ipython docs recommends to modify when subclassing InteractiveShell\n        ip._showtraceback = ipy_display_traceback\n        # add wrapper to capture tb_data\n        ip.showtraceback = ipy_show_traceback\n        ip.showsyntaxerror = lambda *args, **kwargs: ipy_display_traceback(\n            *args, is_syntax=True, **kwargs\n        )\n\n    try:  # pragma: no cover\n        # if within ipython, use customized traceback\n        ip = get_ipython()  # type: ignore[name-defined]\n        ipy_excepthook_closure(ip)\n        return sys.excepthook\n    except Exception:\n        # otherwise use default system hook\n        old_excepthook = sys.excepthook\n        sys.excepthook = excepthook\n        return old_excepthook\n\n\n@dataclass\nclass Frame:\n    filename: str\n    lineno: int\n    name: str\n    line: str = \"\"\n    locals: Optional[Dict[str, pretty.Node]] = None\n    last_instruction: Optional[Tuple[Tuple[int, int], Tuple[int, int]]] = None\n\n\n@dataclass\nclass _SyntaxError:\n    offset: int\n    filename: str\n    line: str\n    lineno: int\n    msg: str\n\n\n@dataclass\nclass Stack:\n    exc_type: str\n    exc_value: str\n    syntax_error: Optional[_SyntaxError] = None\n    is_cause: bool = False\n    frames: List[Frame] = field(default_factory=list)\n\n\n@dataclass\nclass Trace:\n    stacks: List[Stack]\n\n\nclass PathHighlighter(RegexHighlighter):\n    highlights = [r\"(?P<dim>.*/)(?P<bold>.+)\"]\n\n\nclass Traceback:\n    \"\"\"A Console renderable that renders a traceback.\n\n    Args:\n        trace (Trace, optional): A `Trace` object produced from `extract`. Defaults to None, which uses\n            the
5read_file
{
 "end_line": 450,
 "filepath": "rich/traceback.py",
 "start_line": 301
}
{"status": "ok", "filepath": "rich/traceback.py", "content": " exc_type: Type[Any],\n exc_value: BaseException,\n traceback: Optional[TracebackType],\n *,\n wid
full
{"status": "ok", "filepath": "rich/traceback.py", "content": "        exc_type: Type[Any],\n        exc_value: BaseException,\n        traceback: Optional[TracebackType],\n        *,\n        width: Optional[int] = 100,\n        code_width: Optional[int] = 88,\n        extra_lines: int = 3,\n        theme: Optional[str] = None,\n        word_wrap: bool = False,\n        show_locals: bool = False,\n        locals_max_length: int = LOCALS_MAX_LENGTH,\n        locals_max_string: int = LOCALS_MAX_STRING,\n        locals_hide_dunder: bool = True,\n        locals_hide_sunder: bool = False,\n        indent_guides: bool = True,\n        suppress: Iterable[Union[str, ModuleType]] = (),\n        max_frames: int = 100,\n    ) -> \"Traceback\":\n        \"\"\"Create a traceback from exception info\n\n        Args:\n            exc_type (Type[BaseException]): Exception type.\n            exc_value (BaseException): Exception value.\n            traceback (TracebackType): Python Traceback object.\n            width (Optional[int], optional): Number of characters used to traceback. Defaults to 100.\n            code_width (Optional[int], optional): Number of code characters used to traceback. Defaults to 88.\n            extra_lines (int, optional): Additional lines of code to render. Defaults to 3.\n            theme (str, optional): Override pygments theme used in traceback.\n            word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.\n            show_locals (bool, optional): Enable display of local variables. Defaults to False.\n            indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.\n            locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.\n                Defaults to 10.\n            locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.\n            locals_hide_dunder
6read_file
{
 "end_line": 797,
 "filepath": "rich/traceback.py",
 "start_line": 451
}
{"status": "ok", "filepath": "rich/traceback.py", "content": " if sys.version_info >= (3, 11):\n instruction_index = frame_summary.f_lasti // 2\n instruction_po
full
{"status": "ok", "filepath": "rich/traceback.py", "content": "                if sys.version_info >= (3, 11):\n                    instruction_index = frame_summary.f_lasti // 2\n                    instruction_position = next(\n                        islice(\n                            frame_summary.f_code.co_positions(),\n                            instruction_index,\n                            instruction_index + 1,\n                        )\n                    )\n                    (\n                        start_line,\n                        end_line,\n                        start_column,\n                        end_column,\n                    ) = instruction_position\n                    if (\n                        start_line is not None\n                        and end_line is not None\n                        and start_column is not None\n                        and end_column is not None\n                    ):\n                        last_instruction = (\n                            (start_line, start_column),\n                            (end_line, end_column),\n                        )\n\n                if filename and not filename.startswith(\"<\"):\n                    if not os.path.isabs(filename):\n                        filename = os.path.join(_IMPORT_CWD, filename)\n                if frame_summary.f_locals.get(\"_rich_traceback_omit\", False):\n                    continue\n\n                frame = Frame(\n                    filename=filename or \"?\",\n                    lineno=line_no,\n                    name=frame_summary.f_code.co_name,\n                    locals=(\n                        {\n                            key: pretty.traverse(\n                                value,\n                                max_length=locals_max_length,\n                                max_string=locals_max_string,\n                            )\n                            for key, value in get_locals(frame_summary.f_locals.item
7read_file
{
 "end_line": 797,
 "filepath": "rich/traceback.py",
 "start_line": 601
}
{"status": "ok", "filepath": "rich/traceback.py", "content": " )\n else:\n yield Text.from_markup(\n \"\\n[i]During handling of the above exception, another exc
full
{"status": "ok", "filepath": "rich/traceback.py", "content": "                    )\n                else:\n                    yield Text.from_markup(\n                        \"\\n[i]During handling of the above exception, another exception occurred:\\n\",\n                    )\n\n    @group()\n    def _render_syntax_error(self, syntax_error: _SyntaxError) -> RenderResult:\n        highlighter = ReprHighlighter()\n        path_highlighter = PathHighlighter()\n        if syntax_error.filename != \"<stdin>\":\n            if os.path.exists(syntax_error.filename):\n                text = Text.assemble(\n                    (f\" {syntax_error.filename}\", \"pygments.string\"),\n                    (\":\", \"pygments.text\"),\n                    (str(syntax_error.lineno), \"pygments.number\"),\n                    style=\"pygments.text\",\n                )\n                yield path_highlighter(text)\n        syntax_error_text = highlighter(syntax_error.line.rstrip())\n        syntax_error_text.no_wrap = True\n        offset = min(syntax_error.offset - 1, len(syntax_error_text))\n        syntax_error_text.stylize(\"bold underline\", offset, offset)\n        syntax_error_text += Text.from_markup(\n            \"\\n\" + \" \" * offset + \"[traceback.offset]\u25b2[/]\",\n            style=\"pygments.text\",\n        )\n        yield syntax_error_text\n\n    @classmethod\n    def _guess_lexer(cls, filename: str, code: str) -> str:\n        ext = os.path.splitext(filename)[-1]\n        if not ext:\n            # No extension, look at first line to see if it is a hashbang\n            # Note, this is an educated guess and not a guarantee\n            # If it fails, the only downside is that the code is highlighted strangely\n            new_line_index = code.index(\"\\n\")\n            first_line = code[:new_line_index] if new_line_index != -1 else code\n            if first_line.startswith(\"#!\") and \"python\" in first_line.lower():\n                return \"python\"\
8run_command
{
 "command": "python3 -c \"\ntry:\n    raise Exception('Main error')\nexcept Exception as e:\n    e.__notes__ = 'Some important notes'\n    from rich.traceback import Traceback\n    import sys\n    tb = Traceback.from_exception(*sys.exc_info())\n    from rich.console import Console\n    Console().print(tb)\n\""
}
{"status": "ok", "stdout": "\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
full
{"status": "ok", "stdout": "\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Traceback (most recent call last) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n\u2502 in <module>:3                                                                \u2502\n\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\nException: Main error\n", "exit_code": 0}
9read_file
{
 "end_line": 580,
 "filepath": "rich/traceback.py",
 "start_line": 550
}
{"status": "ok", "filepath": "rich/traceback.py", "content": " \"scope.border\": token_style(String.Delimiter),\n \"scope.equals\": token_style(Operator),\n \"s
full
{"status": "ok", "filepath": "rich/traceback.py", "content": "                \"scope.border\": token_style(String.Delimiter),\n                \"scope.equals\": token_style(Operator),\n                \"scope.key\": token_style(Name),\n                \"scope.key.special\": token_style(Name.Constant) + Style(dim=True),\n            },\n            inherit=False,\n        )\n\n        highlighter = ReprHighlighter()\n        for last, stack in loop_last(reversed(self.trace.stacks)):\n            if stack.frames:\n                stack_renderable: ConsoleRenderable = Panel(\n                    self._render_stack(stack),\n                    title=\"[traceback.title]Traceback [dim](most recent call last)\",\n                    style=background_style,\n                    border_style=\"traceback.border\",\n                    expand=True,\n                    padding=(0, 1),\n                )\n                stack_renderable = Constrain(stack_renderable, self.width)\n                with console.use_theme(traceback_theme):\n                    yield stack_renderable\n            if stack.syntax_error is not None:\n                with console.use_theme(traceback_theme):\n                    yield Constrain(\n                        Panel(\n                            self._render_syntax_error(stack.syntax_error),\n                            style=background_style,\n                            border_style=\"traceback.border.syntax_error\",\n                            expand=True,\n                            padding=(0, 1),\n", "start_line": 550, "end_line": 580, "total_lines": 797, "is_truncated": false}
10read_file
{
 "end_line": 600,
 "filepath": "rich/trace.py",
 "start_line": 581
}
{"status": "error", "error_type": "FileNotFound", "error_message": "File not found: rich/trace.py"}
full
{"status": "error", "error_type": "FileNotFound", "error_message": "File not found: rich/trace.py"}
11read_file
{
 "end_line": 600,
 "filepath": "rich/traceback.py",
 "start_line": 581
}
{"status": "ok", "filepath": "rich/traceback.py", "content": " width=self.width,\n ),\n self.width,\n )\n yield Text.assemble(\n (f\"{stack.exc_type}: \", \"tra
full
{"status": "ok", "filepath": "rich/traceback.py", "content": "                            width=self.width,\n                        ),\n                        self.width,\n                    )\n                yield Text.assemble(\n                    (f\"{stack.exc_type}: \", \"traceback.exc_type\"),\n                    highlighter(stack.syntax_error.msg),\n                )\n            elif stack.exc_value:\n                yield Text.assemble(\n                    (f\"{stack.exc_type}: \", \"traceback.exc_type\"),\n                    highlighter(stack.exc_value),\n                )\n            else:\n                yield Text.assemble((f\"{stack.exc_type}\", \"traceback.exc_type\"))\n\n            if not last:\n                if stack.is_cause:\n                    yield Text.from_markup(\n                        \"\\n[i]The above exception was the direct cause of the following exception:\\n\",\n", "start_line": 581, "end_line": 600, "total_lines": 797, "is_truncated": false}
12read_file
{
 "end_line": 420,
 "filepath": "rich/traceback.py",
 "start_line": 400
}
{"status": "ok", "filepath": "rich/traceback.py", "content": "\n stacks: List[Stack] = []\n is_cause = False\n\n from rich import _IMPORT_CWD\n\n def safe_str(_
full
{"status": "ok", "filepath": "rich/traceback.py", "content": "\n        stacks: List[Stack] = []\n        is_cause = False\n\n        from rich import _IMPORT_CWD\n\n        def safe_str(_object: Any) -> str:\n            \"\"\"Don't allow exceptions from __str__ to propagate.\"\"\"\n            try:\n                return str(_object)\n            except Exception:\n                return \"<exception str() failed>\"\n\n        while True:\n            stack = Stack(\n                exc_type=safe_str(exc_type.__name__),\n                exc_value=safe_str(exc_value),\n                is_cause=is_cause,\n            )\n\n            if isinstance(exc_value, SyntaxError):\n", "start_line": 400, "end_line": 420, "total_lines": 797, "is_truncated": false}
13read_file
{
 "end_line": 240,
 "filepath": "rich/traceback.py",
 "start_line": 210
}
{"status": "ok", "filepath": "rich/traceback.py", "content": "class PathHighlighter(RegexHighlighter):\n highlights = [r\"(?P<dim>.*/)(?P<bold>.+)\"]\n\n\nclass
full
{"status": "ok", "filepath": "rich/traceback.py", "content": "class PathHighlighter(RegexHighlighter):\n    highlights = [r\"(?P<dim>.*/)(?P<bold>.+)\"]\n\n\nclass Traceback:\n    \"\"\"A Console renderable that renders a traceback.\n\n    Args:\n        trace (Trace, optional): A `Trace` object produced from `extract`. Defaults to None, which uses\n            the last exception.\n        width (Optional[int], optional): Number of characters used to traceback. Defaults to 100.\n        code_width (Optional[int], optional): Number of code characters used to traceback. Defaults to 88.\n        extra_lines (int, optional): Additional lines of code to render. Defaults to 3.\n        theme (str, optional): Override pygments theme used in traceback.\n        word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.\n        show_locals (bool, optional): Enable display of local variables. Defaults to False.\n        indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.\n        locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.\n            Defaults to 10.\n        locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.\n        locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.\n        locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.\n        suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.\n        max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.\n\n    \"\"\"\n\n    LEXERS = {\n        \"\": \"text\",\n        \".py\": \"python\",\n        \".pxd\": \"cython\",\n", "start_line": 210, "end_line": 240, "total_lines": 797, "is_truncated": false}
14read_file
{
 "end_line": 230,
 "filepath": "rich/traceback.py",
 "start_line": 180
}
{"status": "ok", "filepath": "rich/traceback.py", "content": " lineno: int\n name: str\n line: str = \"\"\n locals: Optional[Dict[str, pretty.Node]] = None\n la
full
{"status": "ok", "filepath": "rich/traceback.py", "content": "    lineno: int\n    name: str\n    line: str = \"\"\n    locals: Optional[Dict[str, pretty.Node]] = None\n    last_instruction: Optional[Tuple[Tuple[int, int], Tuple[int, int]]] = None\n\n\n@dataclass\nclass _SyntaxError:\n    offset: int\n    filename: str\n    line: str\n    lineno: int\n    msg: str\n\n\n@dataclass\nclass Stack:\n    exc_type: str\n    exc_value: str\n    syntax_error: Optional[_SyntaxError] = None\n    is_cause: bool = False\n    frames: List[Frame] = field(default_factory=list)\n\n\n@dataclass\nclass Trace:\n    stacks: List[Stack]\n\n\nclass PathHighlighter(RegexHighlighter):\n    highlights = [r\"(?P<dim>.*/)(?P<bold>.+)\"]\n\n\nclass Traceback:\n    \"\"\"A Console renderable that renders a traceback.\n\n    Args:\n        trace (Trace, optional): A `Trace` object produced from `extract`. Defaults to None, which uses\n            the last exception.\n        width (Optional[int], optional): Number of characters used to traceback. Defaults to 100.\n        code_width (Optional[int], optional): Number of code characters used to traceback. Defaults to 88.\n        extra_lines (int, optional): Additional lines of code to render. Defaults to 3.\n        theme (str, optional): Override pygments theme used in traceback.\n        word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.\n        show_locals (bool, optional): Enable display of local variables. Defaults to False.\n        indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.\n        locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.\n            Defaults to 10.\n        locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.\n        locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.\n", "star
15edit_file
{
 "filepath": "rich/traceback.py",
 "new_string": "@dataclass\nclass Stack:\n    exc_type: str\n    exc_value: str\n    notes: Optional[str] = None\n    syntax_error: Optional[_SyntaxError] = None\n    is_cause: bool = False\n    frames: List[Frame] = field(default_factory=list)",
 "old_string": "@dataclass\nclass Stack:\n    exc_type: str\n    exc_value: str\n    syntax_error: Optional[_SyntaxError] = None\n    is_cause: bool = False\n    frames: List[Frame] = field(default_factory=list)"
}
{"status": "ok", "filepath": "rich/traceback.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/traceback.py\n+++ b/rich/traceback.py\n@@ -197,6 +1
full
{"status": "ok", "filepath": "rich/traceback.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/traceback.py\n+++ b/rich/traceback.py\n@@ -197,6 +197,7 @@\n class Stack:\n     exc_type: str\n     exc_value: str\n+    notes: Optional[str] = None\n     syntax_error: Optional[_SyntaxError] = None\n     is_cause: bool = False\n     frames: List[Frame] = field(default_factory=list)\n", "is_truncated": false}
16edit_file
{
 "filepath": "rich/traceback.py",
 "new_string": "        while True:\n            notes = getattr(exc_value, \"__notes__\", None)\n            stack = Stack(\n                exc_type=safe_str(exc_type.__name__),\n                exc_value=safe_str(exc_value),\n                notes=safe_str(notes) if notes is not None else None,\n                is_cause=is_cause,\n            )",
 "old_string": "        while True:\n            stack = Stack(\n                exc_type=safe_str(exc_type.__name__),\n                exc_value=safe_str(exc_value),\n                is_cause=is_cause,\n            )"
}
{"status": "ok", "filepath": "rich/traceback.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/traceback.py\n+++ b/rich/traceback.py\n@@ -412,9 +4
full
{"status": "ok", "filepath": "rich/traceback.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/traceback.py\n+++ b/rich/traceback.py\n@@ -412,9 +412,11 @@\n                 return \"<exception str() failed>\"\n \n         while True:\n+            notes = getattr(exc_value, \"__notes__\", None)\n             stack = Stack(\n                 exc_type=safe_str(exc_type.__name__),\n                 exc_value=safe_str(exc_value),\n+                notes=safe_str(notes) if notes is not None else None,\n                 is_cause=is_cause,\n             )\n \n", "is_truncated": false}
17edit_file
{
 "filepath": "rich/traceback.py",
 "new_string": "            elif stack.exc_value:\n                yield Text.assemble(\n                    (f\"{stack.exc_type}: \", \"traceback.exc_type\"),\n                    highlighter(stack.exc_value),\n                )\n                if stack.notes:\n                    yield Text.assemble(\n                        (\"\\n\", \"pygments.text\"),\n                        (\"Notes: \", \"traceback.exc_type\"),\n                        highlighter(stack.notes),\n                    )\n            else:",
 "old_string": "            elif stack.exc_value:\n                yield Text.assemble(\n                    (f\"{stack.exc_type}: \", \"traceback.exc_type\"),\n                    highlighter(stack.exc_value),\n                )\n            else:"
}
{"status": "ok", "filepath": "rich/traceback.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/traceback.py\n+++ b/rich/traceback.py\n@@ -594,6 +5
full
{"status": "ok", "filepath": "rich/traceback.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/traceback.py\n+++ b/rich/traceback.py\n@@ -594,6 +594,12 @@\n                     (f\"{stack.exc_type}: \", \"traceback.exc_type\"),\n                     highlighter(stack.exc_value),\n                 )\n+                if stack.notes:\n+                    yield Text.assemble(\n+                        (\"\\n\", \"pygments.text\"),\n+                        (\"Notes: \", \"traceback.exc_type\"),\n+                        highlighter(stack.notes),\n+                    )\n             else:\n                 yield Text.assemble((f\"{stack.exc_type}\", \"traceback.exc_type\"))\n \n", "is_truncated": false}
18run_command
{
 "command": "python3 -c \"\ntry:\n    raise Exception('Main error')\nexcept Exception as e:\n    e.__notes__ = 'Some important notes'\n    from rich.traceback import Traceback\n    import sys\n    tb = Traceback.from_exception(*sys.exc_info())\n    from rich.console import Console\n    Console().print(tb)\n\""
}
{"status": "ok", "stdout": "\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
full
{"status": "ok", "stdout": "\u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Traceback (most recent call last) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n\u2502 in <module>:3                                                                \u2502\n\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\nException: Main error\n\nNotes: Some important notes\n", "exit_code": 0}
19edit_file
{
 "filepath": "rich/traceback.py",
 "new_string": "            if stack.syntax_error is not None:\n                with console.use_theme(traceback_theme):\n                    yield Constrain(\n                        Panel(\n                            self._render_syntax_error(stack.syntax_error),\n                            style=background_style,\n                            border_style=\\\"traceback.border.syntax_error\\\",\n                            expand=True,\n                            padding=(0, 1),\n                            width=self.width,\n                        ),\n                        self.width,\n                    )\n                yield Text.assemble(\n                    (f\\\"{stack.exc_type}: \\\", \\\"traceback.exc_type\\\"),\n                    highlighter(stack.syntax_error.msg),\n                )\n                if stack.notes:\n                    yield Text.assemble(\n                        (\"\\n\", \"pygments.text\"),\n                        (\"Notes: \", \"traceback.exc_type\"),\n                        highlighter(stack.notes),\n                    )\n            elif stack.exc_value:",
 "old_string": "            if stack.syntax_error is not None:\n                with console.use_theme(traceback_theme):\n                    yield Constrain(\n                        Panel(\n                            self._render_syntax_error(stack.syntax_error),\n                            style=background_style,\n                            border_style=\\\"traceback.border.syntax_error\\\",\n                            expand=True,\n                            padding=(0, 1),\n                            width=self.width,\n                        ),\n                        self.width,\n                    )\n                yield Text.assemble(\n                    (f\\\"{stack.exc_type}: \\\", \\\"traceback.exc_type\\\"),\n                    highlighter(stack.syntax_error.msg),\n                )\n            elif stack.exc_value:"
}
{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}
full
{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}
20read_file
{
 "end_line": 595,
 "filepath": "rich/traceback.py",
 "start_line": 570
}
{"status": "ok", "filepath": "rich/traceback.py", "content": " padding=(0, 1),\n )\n stack_renderable = Constrain(stack_renderable, self.width)\n with console.u
full
{"status": "ok", "filepath": "rich/traceback.py", "content": "                    padding=(0, 1),\n                )\n                stack_renderable = Constrain(stack_renderable, self.width)\n                with console.use_theme(traceback_theme):\n                    yield stack_renderable\n            if stack.syntax_error is not None:\n                with console.use_theme(traceback_theme):\n                    yield Constrain(\n                        Panel(\n                            self._render_syntax_error(stack.syntax_error),\n                            style=background_style,\n                            border_style=\"traceback.border.syntax_error\",\n                            expand=True,\n                            padding=(0, 1),\n                            width=self.width,\n                        ),\n                        self.width,\n                    )\n                yield Text.assemble(\n                    (f\"{stack.exc_type}: \", \"traceback.exc_type\"),\n                    highlighter(stack.syntax_error.msg),\n                )\n            elif stack.exc_value:\n                yield Text.assemble(\n                    (f\"{stack.exc_type}: \", \"traceback.exc_type\"),\n                    highlighter(stack.exc_value),\n", "start_line": 570, "end_line": 595, "total_lines": 806, "is_truncated": false}
21edit_file
{
 "filepath": "rich/traceback.py",
 "new_string": "                yield Text.assemble(\n                    (f\"{stack.exc_type}: \", \"traceback.exc_type\"),\n                    highlighter(stack.syntax_error.msg),\n                )\n                if stack.notes:\n                    yield Text.assemble(\n                        (\"\\n\", \"pygments.text\"),\n                        (\"Notes: \", \"traceback.exc_type\"),\n                        highlighter(stack.notes),\n                    )\n            elif stack.exc_value:",
 "old_string": "                yield Text.assemble(\n                    (f\"{stack.exc_type}: \", \"traceback.exc_type\"),\n                    highlighter(stack.syntax_error.msg),\n                )\n            elif stack.exc_value:"
}
{"status": "ok", "filepath": "rich/traceback.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/traceback.py\n+++ b/rich/traceback.py\n@@ -589,6 +5
full
{"status": "ok", "filepath": "rich/traceback.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/traceback.py\n+++ b/rich/traceback.py\n@@ -589,6 +589,12 @@\n                     (f\"{stack.exc_type}: \", \"traceback.exc_type\"),\n                     highlighter(stack.syntax_error.msg),\n                 )\n+                if stack.notes:\n+                    yield Text.assemble(\n+                        (\"\\n\", \"pygments.text\"),\n+                        (\"Notes: \", \"traceback.exc_type\"),\n+                        highlighter(stack.notes),\n+                    )\n             elif stack.exc_value:\n                 yield Text.assemble(\n                     (f\"{stack.exc_type}: \", \"traceback.exc_type\"),\n", "is_truncated": false}
22submit_patch
[]
{"status": "ok", "patch_size": 1831, "files_changed": 1}
full
{"status": "ok", "patch_size": 1831, "files_changed": 1}

Patch

diff --git a/rich/traceback.py b/rich/traceback.py
index 3bf5baa7..dc6857f8 100644
--- a/rich/traceback.py
+++ b/rich/traceback.py
@@ -197,6 +197,7 @@ class _SyntaxError:
 class Stack:
     exc_type: str
     exc_value: str
+    notes: Optional[str] = None
     syntax_error: Optional[_SyntaxError] = None
     is_cause: bool = False
     frames: List[Frame] = field(default_factory=list)
@@ -411,9 +412,11 @@ class Traceback:
                 return "<exception str() failed>"
 
         while True:
+            notes = getattr(exc_value, "__notes__", None)
             stack = Stack(
                 exc_type=safe_str(exc_type.__name__),
                 exc_value=safe_str(exc_value),
+                notes=safe_str(notes) if notes is not None else None,
                 is_cause=is_cause,
             )
 
@@ -586,11 +589,23 @@ class Traceback:
                     (f"{stack.exc_type}: ", "traceback.exc_type"),
                     highlighter(stack.syntax_error.msg),
                 )
+                if stack.notes:
+                    yield Text.assemble(
+                        ("\n", "pygments.text"),
+                        ("Notes: ", "traceback.exc_type"),
+                        highlighter(stack.notes),
+                    )
             elif stack.exc_value:
                 yield Text.assemble(
                     (f"{stack.exc_type}: ", "traceback.exc_type"),
                     highlighter(stack.exc_value),
                 )
+                if stack.notes:
+                    yield Text.assemble(
+                        ("\n", "pygments.text"),
+                        ("Notes: ", "traceback.exc_type"),
+                        highlighter(stack.notes),
+                    )
             else:
                 yield Text.assemble((f"{stack.exc_type}", "traceback.exc_type"))
 

Test output

show
...................s.F
=================================== FAILURES ===================================
__________________________________ test_notes __________________________________

    @pytest.mark.skipif(
        sys.version_info.minor < 11, reason="Not supported before Python 3.11"
    )
    def test_notes() -> None:
        """Check traceback captures __note__."""
        try:
>           1 / 0
E           ZeroDivisionError: division by zero
E           Hello
E           World

tests/test_traceback.py:369: ZeroDivisionError

During handling of the above exception, another exception occurred:

    @pytest.mark.skipif(
        sys.version_info.minor < 11, reason="Not supported before Python 3.11"
    )
    def test_notes() -> None:
        """Check traceback captures __note__."""
        try:
            1 / 0
        except Exception as error:
            error.add_note("Hello")
            error.add_note("World")
            traceback = Traceback()
    
>           assert traceback.trace.stacks[0].notes == ["Hello", "World"]
E           assert "['Hello', 'World']" == ['Hello', 'World']
E            +  where "['Hello', 'World']" = Stack(exc_type='ZeroDivisionError', exc_value='division by zero', notes="['Hello', 'World']", syntax_error=None, is_ca...sts/test_traceback.py', lineno=369, name='test_notes', line='', locals=None, last_instruction=((373, 20), (373, 31)))]).notes

tests/test_traceback.py:375: AssertionError
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 20 passed, 1 skipped in 1.15s