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

Handle dataclasses with unitialized fields in pretty printing #3418

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Progress track thread is now a daemon thread https://github.com/Textualize/rich/pull/3402
- Fixed cached hash preservation upon clearing meta and links https://github.com/Textualize/rich/issues/2942
- Fixed overriding the `background_color` of `Syntax` not including padding https://github.com/Textualize/rich/issues/3295
- Fixed pretty printing of dataclasses with uninitialized fields https://github.com/Textualize/rich/issues/3417

### Changed

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ The following people have contributed to the development of Rich:
- [Pierro](https://github.com/xpierroz)
- [Bernhard Wagner](https://github.com/bwagner)
- [Aaron Beaudoin](https://github.com/AaronBeaudoin)
- [Collin Heist](https://github.com/CollinHeist/)
6 changes: 5 additions & 1 deletion rich/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,11 @@ def iter_attrs() -> (
for last, field in loop_last(
field for field in fields(obj) if field.repr
):
child_node = _traverse(getattr(obj, field.name), depth=depth + 1)
try:
child_node = _traverse(getattr(obj, field.name), depth=depth + 1)
except AttributeError:
continue

child_node.key_repr = field.name
child_node.last = last
child_node.key_separator = "="
Expand Down