Skip to content

Commit ef8f231

Browse files
committed
Handle dataclasses with Python 3.13 default repr
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
1 parent e1e6d74 commit ef8f231

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rich/pretty.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dataclasses
44
import inspect
55
import os
6+
import reprlib
67
import sys
78
from array import array
89
from collections import Counter, UserDict, UserList, defaultdict, deque
@@ -78,7 +79,10 @@ def _is_dataclass_repr(obj: object) -> bool:
7879
# Digging in to a lot of internals here
7980
# Catching all exceptions in case something is missing on a non CPython implementation
8081
try:
81-
return obj.__repr__.__code__.co_filename == dataclasses.__file__
82+
return obj.__repr__.__code__.co_filename in (
83+
dataclasses.__file__,
84+
reprlib.__file__,
85+
)
8286
except Exception: # pragma: no coverage
8387
return False
8488

0 commit comments

Comments
 (0)