Merge pull request #2820 from Textualize/empty-dataclass

fix for empty dataclass
This commit is contained in:
Will McGugan 2023-02-19 22:59:38 +00:00 committed by GitHub
commit cba485f6c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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