fix for empty dataclass

This commit is contained in:
Will McGugan 2023-02-19 22:51:55 +00:00
parent b89d0362e8
commit da4f6bc797
3 changed files with 17 additions and 0 deletions

View file

@ -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

View file

@ -793,6 +793,7 @@ def traverse(
close_brace=")",
children=children,
last=root,
empty=f"{obj.__class__.__name__}()",
)
for last, field in loop_last(

View file

@ -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