Skip to content

Commit

Permalink
Handle dataclasses with Python 3.13 default repr
Browse files Browse the repository at this point in the history
The reprlib module is used for the default __repr__ method in
dataclasses starting in Python 3.13.

Allow this module to also be an indication that a dataclass has the
default __repr__.

closes #3368
  • Loading branch information
jjhelmus committed Aug 16, 2024
1 parent e1e6d74 commit ef8f231
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rich/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dataclasses
import inspect
import os
import reprlib
import sys
from array import array
from collections import Counter, UserDict, UserList, defaultdict, deque
Expand Down Expand Up @@ -78,7 +79,10 @@ def _is_dataclass_repr(obj: object) -> bool:
# Digging in to a lot of internals here
# Catching all exceptions in case something is missing on a non CPython implementation
try:
return obj.__repr__.__code__.co_filename == dataclasses.__file__
return obj.__repr__.__code__.co_filename in (
dataclasses.__file__,
reprlib.__file__,
)
except Exception: # pragma: no coverage
return False

Expand Down

0 comments on commit ef8f231

Please sign in to comment.