@@ -517,11 +517,7 @@ def _default_pprint(obj, p, cycle):
517517 klass = _safe_getattr (obj , '__class__' , None ) or type (obj )
518518 if _safe_getattr (klass , '__repr__' , None ) not in _baseclass_reprs :
519519 # A user-provided repr. Find newlines and replace them with p.break_()
520- output = repr (obj )
521- for idx ,output_line in enumerate (output .splitlines ()):
522- if idx :
523- p .break_ ()
524- p .text (output_line )
520+ _repr_pprint (obj , p , cycle )
525521 return
526522 p .begin_group (1 , '<' )
527523 p .pretty (klass )
@@ -682,6 +678,12 @@ def _type_pprint(obj, p, cycle):
682678 """The pprint for classes and types."""
683679 # Heap allocated types might not have the module attribute,
684680 # and others may set it to None.
681+
682+ # Checks for a __repr__ override in the metaclass
683+ if type (obj ).__repr__ is not type .__repr__ :
684+ _repr_pprint (obj , p , cycle )
685+ return
686+
685687 mod = _safe_getattr (obj , '__module__' , None )
686688 name = _safe_getattr (obj , '__qualname__' , obj .__name__ )
687689
@@ -693,7 +695,12 @@ def _type_pprint(obj, p, cycle):
693695
694696def _repr_pprint (obj , p , cycle ):
695697 """A pprint that just redirects to the normal repr function."""
696- p .text (repr (obj ))
698+ # Find newlines and replace them with p.break_()
699+ output = repr (obj )
700+ for idx ,output_line in enumerate (output .splitlines ()):
701+ if idx :
702+ p .break_ ()
703+ p .text (output_line )
697704
698705
699706def _function_pprint (obj , p , cycle ):
0 commit comments