@@ -118,9 +118,16 @@ def __float__(self) -> float:
118118
119119 def __format__ (self , format_spec : str ) -> str :
120120 match format_spec :
121- case "" : return self .string ()
122- case "t" : return self .string ().replace ("-" , "~" )
123- case _: return format (self .decimal (), format_spec )
121+ case "" :
122+ return self .string ()
123+ case "t" :
124+ return self .string ().replace ("-" , "~" )
125+ case _:
126+ try :
127+ return format (self .decimal (), format_spec )
128+
129+ except (TypeError , ValueError ):
130+ return super ().__format__ (format_spec )
124131
125132 def __int__ (self ) -> int :
126133 return self .int ()
@@ -287,9 +294,16 @@ def __complex__(self):
287294
288295 def __format__ (self , format_spec : str ) -> str :
289296 match format_spec :
290- case "" : return self .string ()
291- case "t" : return squash (replacer (self .string (), {"i" : "[i]" , "-" : "~" , "~ " : "- " }))
292- case _: return format (self .complex (), format_spec )
297+ case "" :
298+ return self .string ()
299+ case "t" :
300+ return squash (replacer (self .string (), {"i" : "[i]" , "-" : "~" , "~ " : "- " }))
301+ case _:
302+ try :
303+ return format (self .complex (), format_spec )
304+
305+ except (TypeError , ValueError ):
306+ return super ().__format__ (format_spec )
293307
294308 @Section (min_data_length )
295309 def data (self ) -> bytearray :
0 commit comments