← mined_oracle

rich_2558

failed WRONG_FIX UNSUBMITTED wrong_fix_unsubmitted(None) · None tool calls · 0 s · Textualize/rich

Task input

(not found in data/tasks.jsonl)

Tool calls (0)

#ToolArgumentsResult
No trace captured.

Patch

--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Fix missing `mode` property on file wrapper breaking uploads via `requests` https://github.com/Textualize/rich/pull/2495
 - Fix mismatching default value of parameter `ensure_ascii` https://github.com/Textualize/rich/pull/2538
 - Remove unused height parameter in `Layout` class https://github.com/Textualize/rich/pull/2540
+- Fixed exception in Syntax.__rich_measure__ for empty files
 
 
 ### Changed
--- a/rich/syntax.py
+++ b/rich/syntax.py
@@ -593,10 +593,11 @@ class Syntax(JupyterMixin):
         if self.code_width is not None:
             width = self.code_width + self._numbers_column_width + padding + 1
             return Measurement(self._numbers_column_width, width)
+        lines = self.code.splitlines()
         width = (
             self._numbers_column_width
             + padding
-            + max(cell_len(line) for line in self.code.splitlines())
+            + (max(cell_len(line) for line in lines) if lines else 0)
         )
         if self.line_numbers:
             width += 1

Test output

show
F
=================================== FAILURES ===================================
_______________________________ test_blank_lines _______________________________

    def test_blank_lines():
        code = "\n\nimport this\n\n"
        syntax = Syntax(
            code, lexer="python", theme="ascii_light", code_width=30, line_numbers=True
        )
        result = render(syntax)
        print(repr(result))
>       assert (
            result
            == "\x1b[1;38;2;24;24;24;48;2;248;248;248m  \x1b[0m\x1b[38;2;173;173;173;48;2;248;248;248m1 \x1b[0m\x1b[48;2;248;248;248m                              \x1b[0m\n\x1b[1;38;2;24;24;24;48;2;248;248;248m  \x1b[0m\x1b[38;2;173;173;173;48;2;248;248;248m2 \x1b[0m\x1b[48;2;248;248;248m                              \x1b[0m\n\x1b[1;38;2;24;24;24;48;2;248;248;248m  \x1b[0m\x1b[38;2;173;173;173;48;2;248;248;248m3 \x1b[0m\x1b[1;38;2;0;128;0;48;2;248;248;248mimport\x1b[0m\x1b[38;2;0;0;0;48;2;248;248;248m \x1b[0m\x1b[1;38;2;0;0;255;48;2;248;248;248mthis\x1b[0m\x1b[48;2;248;248;248m                   \x1b[0m\n\x1b[1;38;2;24;24;24;48;2;248;248;248m  \x1b[0m\x1b[38;2;173;173;173;48;2;248;248;248m4 \x1b[0m\x1b[48;2;248;248;248m                              \x1b[0m\n\x1b[1;38;2;24;24;24;48;2;248;248;248m  \x1b[0m\x1b[38;2;173;173;173;48;2;248;248;248m5 \x1b[0m\x1b[48;2;248;248;248m                              \x1b[0m\n"
        )
E       AssertionError: assert '\x1b[1m  \x1...           \n' == '\x1b[1;38;2;...    \x1b[0m\n'
E         
E         -   1                               
E         -   2                               
E         -   3 import this                   
E         -   [38;2;17...
E         
E         ...Full output truncated (7 lines hidden), use '-vv' to show

tests/test_syntax.py:46: AssertionError
----------------------------- Captured stdout call -----------------------------
'\x1b[1m  \x1b[0m1                               \n\x1b[1m  \x1b[0m2                               \n\x1b[1m  \x1b[0m3 \x1b[1mimport\x1b[0m \x1b[1mthis\x1b[0m                   \n\x1b[1m  \x1b[0m4                               \n\x1b[1m  \x1b[0m5                               \n'
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed in 0.17s