@@ -643,11 +643,22 @@ def _format_pprint(self, object, method, context, maxlevels, level):
643643 formatted , is_readable , _ = self .format (value , context , maxlevels , level + 1 )
644644 parts .append (f"{ name } ={ formatted } " )
645645 readable = readable and is_readable
646- case (name , value ):
646+ case (str () as name , value ) if name :
647647 # Keyword argument. Always show.
648648 formatted , is_readable , _ = self .format (value , context , maxlevels , level + 1 )
649649 parts .append (f"{ name } ={ formatted } " )
650650 readable = readable and is_readable
651+ case (name , value ) if not name :
652+ # 2-tuple with a false-y name: treat as positional.
653+ formatted , is_readable , _ = self .format (value , context , maxlevels , level + 1 )
654+ parts .append (formatted )
655+ readable = readable and is_readable
656+ case (name , value ):
657+ # Truthy non-string name is an error.
658+ raise ValueError (
659+ f"__pprint__ yielded a 2-tuple with "
660+ f"non-string name: { name !r} "
661+ )
651662 case _:
652663 # Positional argument.
653664 formatted , is_readable , _ = self .format (item , context , maxlevels , level + 1 )
0 commit comments