@@ -735,6 +735,61 @@ def _pprint_user_string(self, object, stream, indent, allowance, context, level)
735735
736736 _dispatch [_collections .UserString .__repr__ ] = _pprint_user_string
737737
738+ def _pprint_template (self , object , stream , indent , allowance , context , level ):
739+ cls_name = object .__class__ .__name__
740+ if self ._expand :
741+ indent += self ._indent_per_level
742+ else :
743+ indent += len (cls_name ) + 1
744+
745+ items = (
746+ ("strings" , object .strings ),
747+ ("interpolations" , object .interpolations ),
748+ )
749+ stream .write (self ._format_block_start (cls_name + "(" , indent ))
750+ self ._format_namespace_items (
751+ items , stream , indent , allowance , context , level
752+ )
753+ stream .write (
754+ self ._format_block_end (")" , indent - self ._indent_per_level )
755+ )
756+
757+ def _pprint_interpolation (self , object , stream , indent , allowance , context , level ):
758+ cls_name = object .__class__ .__name__
759+ if self ._expand :
760+ indent += self ._indent_per_level
761+ items = (
762+ ("value" , object .value ),
763+ ("expression" , object .expression ),
764+ ("conversion" , object .conversion ),
765+ ("format_spec" , object .format_spec ),
766+ )
767+ stream .write (self ._format_block_start (cls_name + "(" , indent ))
768+ self ._format_namespace_items (
769+ items , stream , indent , allowance , context , level
770+ )
771+ stream .write (
772+ self ._format_block_end (")" , indent - self ._indent_per_level )
773+ )
774+ else :
775+ indent += len (cls_name )
776+ items = (
777+ object .value ,
778+ object .expression ,
779+ object .conversion ,
780+ object .format_spec ,
781+ )
782+ stream .write (cls_name + "(" )
783+ self ._format_items (
784+ items , stream , indent , allowance , context , level
785+ )
786+ stream .write (")" )
787+
788+ t = t "{0}"
789+ _dispatch [type (t ).__repr__ ] = _pprint_template
790+ _dispatch [type (t .interpolations [0 ]).__repr__ ] = _pprint_interpolation
791+ del t
792+
738793 def _safe_repr (self , object , context , maxlevels , level ):
739794 # Return triple (repr_string, isreadable, isrecursive).
740795 typ = type (object )
0 commit comments