mirror of https://github.com/Textualize/rich.git
Merge pull request #2820 from Textualize/empty-dataclass
fix for empty dataclass
This commit is contained in:
commit
cba485f6c4
|
@ -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
|
||||
|
|
|
@ -793,6 +793,7 @@ def traverse(
|
|||
close_brace=")",
|
||||
children=children,
|
||||
last=root,
|
||||
empty=f"{obj.__class__.__name__}()",
|
||||
)
|
||||
|
||||
for last, field in loop_last(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue