33from collections import OrderedDict
44from collections .abc import Generator
55
6- from .utils import LazyIsInstance , isatty
6+ from .utils import isatty
77
88__all__ = 'PrettyFormat' , 'pformat' , 'pprint'
99MYPY = False
1818DEFAULT_WIDTH = int (os .getenv ('PY_DEVTOOLS_WIDTH' , 120 ))
1919MISSING = object ()
2020PRETTY_KEY = '__prettier_formatted_value__'
21- MultiDict = LazyIsInstance ['multidict' , 'MultiDict' ]
2221
2322
2423def env_true (var_name , alt = None ):
@@ -70,7 +69,6 @@ def __init__(
7069 (tuple , self ._format_tuples ),
7170 ((list , set , frozenset ), self ._format_list_like ),
7271 (Generator , self ._format_generators ),
73- (MultiDict , self ._format_dict ),
7472 ]
7573
7674 def __call__ (self , value : 'Any' , * , indent : int = 0 , indent_first : bool = False , highlight : bool = False ):
@@ -114,6 +112,14 @@ def _format(self, value: 'Any', indent_current: int, indent_first: bool):
114112 if isinstance (value , t ):
115113 func (value , value_repr , indent_current , indent_new )
116114 return
115+
116+ # very blunt check for things that look like dictionaries but do not necessarily inherit from Mapping
117+ # e.g. asyncpg Records
118+ # HELP: are there any other checks we should include here?
119+ if hasattr (value , '__getitem__' ) and hasattr (value , 'items' ) and callable (value .items ):
120+ self ._format_dict (value , value_repr , indent_current , indent_new )
121+ return
122+
117123 self ._format_raw (value , value_repr , indent_current , indent_new )
118124
119125 def _render_pretty (self , gen , indent : int ):
@@ -136,13 +142,13 @@ def _render_pretty(self, gen, indent: int):
136142 # shouldn't happen but will
137143 self ._stream .write (repr (v ))
138144
139- def _format_dict (self , value : dict , value_repr : str , indent_current : int , indent_new : int ):
145+ def _format_dict (self , value : 'Any' , value_repr : str , indent_current : int , indent_new : int ):
140146 open_ , before_ , split_ , after_ , close_ = '{\n ' , indent_new * self ._c , ': ' , ',\n ' , '}'
141147 if isinstance (value , OrderedDict ):
142148 open_ , split_ , after_ , close_ = 'OrderedDict([\n ' , ', ' , '),\n ' , '])'
143149 before_ += '('
144- elif isinstance (value , MultiDict ):
145- open_ , close_ = '<{}(\n ' .format (value .__class__ .__name__ ), ')>'
150+ elif not isinstance (value , dict ):
151+ open_ , close_ = '<{}({{ \n ' .format (value .__class__ .__name__ ), '} )>'
146152
147153 self ._stream .write (open_ )
148154 for k , v in value .items ():
0 commit comments