diff --git a/CHANGELOG.md b/CHANGELOG.md index 26effda4..b8cfd514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [13.3.2] - Unreleased + +### Fixed + +- Fixed pretty printing of empty dataclass https://github.com/Textualize/rich/issues/2819 + ## [13.3.1] - 2023-01-28 ### Fixed diff --git a/rich/pretty.py b/rich/pretty.py index 83c6c1e6..f257b15a 100644 --- a/rich/pretty.py +++ b/rich/pretty.py @@ -793,6 +793,7 @@ def traverse( close_brace=")", children=children, last=root, + empty=f"{obj.__class__.__name__}()", ) for last, field in loop_last( diff --git a/tests/test_pretty.py b/tests/test_pretty.py index 53256379..46dd57a8 100644 --- a/tests/test_pretty.py +++ b/tests/test_pretty.py @@ -175,6 +175,11 @@ class ExampleDataclass: last: int = field(default=1, repr=False) +@dataclass +class Empty: + pass + + def test_pretty_dataclass(): dc = ExampleDataclass(1000, "Hello, World", 999, ["foo", "bar", "baz"]) result = pretty_repr(dc, max_width=80) @@ -195,6 +200,11 @@ def test_pretty_dataclass(): assert result == "ExampleDataclass(foo=1000, bar=..., baz=['foo', 'bar', 'baz'])" +def test_empty_dataclass(): + assert pretty_repr(Empty()) == "Empty()" + assert pretty_repr([Empty()]) == "[Empty()]" + + class StockKeepingUnit(NamedTuple): name: str description: str