@@ -609,6 +609,40 @@ def check_format(expected, format, *args):
609609 check_format ('xyz' ,
610610 b'%V' , None , b'xyz' )
611611
612+ # test %T
613+ check_format ('type: str' ,
614+ b'type: %T' , py_object ("abc" ))
615+ check_format (f'type: st' ,
616+ b'type: %.2T' , py_object ("abc" ))
617+ check_format (f'type: str' ,
618+ b'type: %10T' , py_object ("abc" ))
619+
620+ class LocalType :
621+ pass
622+ obj = LocalType ()
623+ fullname = f'{ __name__ } .{ LocalType .__qualname__ } '
624+ check_format (f'type: { fullname } ' ,
625+ b'type: %T' , py_object (obj ))
626+ fullname_alt = f'{ __name__ } :{ LocalType .__qualname__ } '
627+ check_format (f'type: { fullname_alt } ' ,
628+ b'type: %T#' , py_object (obj ))
629+
630+ # test %N
631+ check_format ('type: str' ,
632+ b'type: %N' , py_object (str ))
633+ check_format (f'type: st' ,
634+ b'type: %.2N' , py_object (str ))
635+ check_format (f'type: str' ,
636+ b'type: %10N' , py_object (str ))
637+
638+ check_format (f'type: { fullname } ' ,
639+ b'type: %N' , py_object (type (obj )))
640+ check_format (f'type: { fullname_alt } ' ,
641+ b'type: %N#' , py_object (type (obj )))
642+ with self .assertRaisesRegex (TypeError , "%N argument must be a type" ):
643+ check_format ('type: str' ,
644+ b'type: %N' , py_object ("abc" ))
645+
612646 # test %ls
613647 check_format ('abc' , b'%ls' , c_wchar_p ('abc' ))
614648 check_format ('\u4eba \u6c11 ' , b'%ls' , c_wchar_p ('\u4eba \u6c11 ' ))
0 commit comments