Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Test failures with Python 3.13.0b1: test_pretty.py and dataclass repr #3368

Closed
2 tasks done
befeleme opened this issue May 31, 2024 · 3 comments · Fixed by #3455
Closed
2 tasks done

[BUG] Test failures with Python 3.13.0b1: test_pretty.py and dataclass repr #3368

befeleme opened this issue May 31, 2024 · 3 comments · Fixed by #3455

Comments

@befeleme
Copy link
Contributor

Describe the bug

3 of test_pretty fail with Python 3.13.0b1:

=================================== 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 "ExampleDataclass(foo=1000, bar='Hello, World', baz=['foo', 'bar', 'baz'])" == "ExampleDataclass(\n    foo=1000,\n    bar='Hello, World',\n    baz=[\n        'foo',\n        'bar',\n        'baz'\n    ]\n)"
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         -         'bar',
E         -         'baz'
E         -     ]
E         - )

tests/test_pretty.py:184: AssertionError
----------------------------- Captured stdout call -----------------------------
"ExampleDataclass(foo=1000, bar='Hello, World', baz=['foo', 'bar', 'baz'])"
"ExampleDataclass(foo=1000, bar='Hello, World', baz=['foo', 'bar', 'baz'])"
________________________ test_reference_cycle_dataclass ________________________

    def test_reference_cycle_dataclass():
        @dataclass
        class Example:
            x: int
            y: Any
    
        test = Example(1, None)
        test.y = test
        res = pretty_repr(test)
>       assert res == "Example(x=1, y=...)"
E       AssertionError: assert 'test_reference_cycle_dataclass.<locals>.Example(x=1, y=...)' == 'Example(x=1, y=...)'
E         - Example(x=1, y=...)
E         + test_reference_cycle_dataclass.<locals>.Example(x=1, y=...)

tests/test_pretty.py:356: AssertionError
___________________________ test_max_depth_dataclass ___________________________

    def test_max_depth_dataclass():
        @dataclass
        class Foo:
            foo: object
    
        @dataclass
        class Bar:
            bar: object
    
>       assert (
            pretty_repr(Foo(foo=Bar(bar=Foo(foo=[]))), max_depth=2)
            == "Foo(foo=Bar(bar=Foo(...)))"
        )
E       AssertionError: assert 'test_max_depth_dataclass.<locals>.Foo(foo=test_max_depth_dataclass.<locals>.Bar(bar=test_max_depth_dataclass.<locals>.Foo(foo=[])))' == 'Foo(foo=Bar(bar=Foo(...)))'
E         - Foo(foo=Bar(bar=Foo(...)))
E         + test_max_depth_dataclass.<locals>.Foo(foo=test_max_depth_dataclass.<locals>.Bar(bar=test_max_depth_dataclass.<locals>.Foo(foo=[])))

tests/test_pretty.py:487: AssertionError
=========================== short test summary info ============================
FAILED tests/test_pretty.py::test_pretty_dataclass - assert "ExampleDataclass...
FAILED tests/test_pretty.py::test_reference_cycle_dataclass - AssertionError:...
FAILED tests/test_pretty.py::test_max_depth_dataclass - AssertionError: asser...
============= 3 failed, 799 passed, 24 skipped, 1 warning in 4.76s =============

Edit this with a clear and concise description of what the bug.

Provide a minimal code example that demonstrates the issue if you can. If the issue is visual in nature, consider posting a screenshot.

Platform

Click to expand

Fedora Linux 41

Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

jjhelmus added a commit to jjhelmus/rich that referenced this issue Aug 16, 2024
The reprlib module is used for the default __repr__ method in
dataclasses starting in Python 3.13.

Allow this module to also be an indication that a dataclass has the
default __repr__.

closes Textualize#3368
Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

1 similar comment
Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant