← mined_oracle

rich_2864

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
@@ -117,6 +117,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Added Style.clear_meta_and_links
 
+## Unreleased
+
+### Fixed
+
+- Fix pretty repr for `collections.deque` https://github.com/Textualize/rich/pull/2864
+
 ## [13.3.2] - 2023-02-04
 
 ### Fixed
--- a/rich/pretty.py
+++ b/rich/pretty.py
@@ -15,6 +15,7 @@ from typing import (
     Any,
     Callable,
     DefaultDict,
+    Deque,
     Dict,
     Iterable,
     List,
@@ -357,6 +358,12 @@ def _get_braces_for_defaultdict(_object: DefaultDict[Any, Any]) -> Tuple[str, st
     )
 
 
+def _get_braces_for_deque(_object: Deque[Any]) -> Tuple[str, str, str]:
+    if _object.maxlen is None:
+        return ("deque([", "])", "deque()")
+    return ("deque([", f"], maxlen={_object.maxlen})", f"deque(maxlen={_object.maxlen})")
+
+
 def _get_braces_for_array(_object: "array[Any]") -> Tuple[str, str, str]:
     return (f"array({_object.typecode!r}, [", "])", f"array({_object.typecode!r})")
 
@@ -366,7 +373,7 @@ _BRACES: Dict[type, Callable[[Any], Tuple[str, str, str]]] = {
     array: _get_braces_for_array,
     defaultdict: _get_braces_for_defaultdict,
     Counter: lambda _object: ("Counter({", "})", "Counter()"),
-    deque: lambda _object: ("deque([", "])", "deque()"),
+    deque: _get_braces_for_deque,
     dict: lambda _object: ("{", "}", "{}"),
     UserDict: lambda _object: ("{", "}", "{}"),
     frozenset: lambda _object: ("frozenset({", "})", "frozenset()"),

Test output

show
........F
=================================== FAILURES ===================================
____________________________ test_pretty_dataclass _____________________________

    def test_pretty_dataclass():
        dc = ExampleDataclass(1000, "Hello, World", 999, ["foo", "bar", "baz"])
        result = pretty_repr(dc, max_width=80)
        print(repr(result))
        assert (
            result
            == "ExampleDataclass(foo=1000, bar='Hello, World', baz=['foo', 'bar', 'baz'])"
        )
        result = pretty_repr(dc, max_width=16)
        print(repr(result))
>       assert (
            result
            == "ExampleDataclass(\n    foo=1000,\n    bar='Hello, World',\n    baz=[\n        'foo',\n        'bar',\n        'baz'\n    ]\n)"
        )
E       assert "ExampleDatac...bar', 'baz'])" == "ExampleDatac...az'\n    ]\n)"
E         
E         + ExampleDataclass(foo=1000, bar='Hello, World', baz=['foo', 'bar', 'baz'])
E         - ExampleDataclass(
E         -     foo=1000,
E         -     bar='Hello, World',
E         -     baz=[
E         -         'foo',...
E         
E         ...Full output truncated (4 lines hidden), use '-vv' to show

tests/test_pretty.py:180: AssertionError
----------------------------- Captured stdout call -----------------------------
"ExampleDataclass(foo=1000, bar='Hello, World', baz=['foo', 'bar', 'baz'])"
"ExampleDataclass(foo=1000, bar='Hello, World', baz=['foo', 'bar', 'baz'])"
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 8 passed in 0.14s