← oracle_full

rich_3472

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

Task input

fix for missing field in dataclass

Fixes https://github.com/Textualize/rich/issues/3417

Tool calls (0)

#ToolArgumentsResult
No trace captured.

Patch

--- a/rich/pretty.py
+++ b/rich/pretty.py
@@ -781,7 +781,9 @@ def iter_attrs() -> (
                 )
 
                 for last, field in loop_last(
-                    field for field in fields(obj) if field.repr
+                    field
+                    for field in fields(obj)
+                    if field.repr and hasattr(obj, field.name)
                 ):
                     child_node = _traverse(getattr(obj, field.name), depth=depth + 1)
                     child_node.key_repr = field.name

Test output

show
............................................sF
=================================== FAILURES ===================================
____________________________ test_attrs_broken_310 _____________________________

    @skip_py37
    @skip_py38
    @skip_py39
    def test_attrs_broken_310() -> None:
        @attr.define
        class Foo:
            bar: int
    
        foo = Foo(1)
        del foo.bar
        result = pretty_repr(foo)
        print(repr(result))
        expected = "Foo(bar=AttributeError(\"'Foo' object has no attribute 'bar'\"))"
>       assert result == expected
E       assert 'Foo(\n    ba... \'bar\'")\n)' == 'Foo(bar=Attr...te \'bar\'"))'
E         
E         - Foo(bar=AttributeError("'Foo' object has no attribute 'bar'"))
E         + Foo(
E         +     bar=AttributeError("'tests.test_pretty.test_attrs_broken_310.<locals>.Foo' object has no attribute 'bar'")
E         + )

tests/test_pretty.py:672: AssertionError
----------------------------- Captured stdout call -----------------------------
'Foo(\n    bar=AttributeError("\'tests.test_pretty.test_attrs_broken_310.<locals>.Foo\' object has no attribute \'bar\'")\n)'
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 44 passed, 1 skipped in 0.15s