Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
48.31k stars 1.7k forks source link

[BUG] Dataclass attributes specified with `init=False` cause error in pretty printing #3417

Open CollinHeist opened 2 weeks ago

CollinHeist commented 2 weeks ago

Describe the bug

Objects in pretty traceback printing which are dataclass objects with fields that are specified with init=False will cause an uncaught exception in the printing. See below.

from dataclasses import dataclass, field, fields

@dataclass(eq=False)
class BadDataclass:
    item: int = field(init=False)

# item is not provided
ob = BadDataclass()

# Displays all fields, including item
print([f for f in fields(ob) if f.repr])

# Raises an AttributeError since ob.item is not defined
print([getattr(ob, f.name) for f in fields(ob)])

This is specifically caused by this line of code.

PR Submitted

github-actions[bot] commented 2 weeks ago

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory