@@ -650,6 +650,40 @@ def check_format(expected, format, *args):
650650 check_format ('\U0001f4bb +' if sizeof (c_wchar ) > 2 else '\U0001f4bb ' ,
651651 b'%.2lV' , None , c_wchar_p ('\U0001f4bb +\U0001f40d ' ))
652652
653+ # test %T
654+ check_format ('type: str' ,
655+ b'type: %T' , py_object ("abc" ))
656+ check_format (f'type: st' ,
657+ b'type: %.2T' , py_object ("abc" ))
658+ check_format (f'type: str' ,
659+ b'type: %10T' , py_object ("abc" ))
660+
661+ class LocalType :
662+ pass
663+ obj = LocalType ()
664+ fullname = f'{ __name__ } .{ LocalType .__qualname__ } '
665+ check_format (f'type: { fullname } ' ,
666+ b'type: %T' , py_object (obj ))
667+ fullname_alt = f'{ __name__ } :{ LocalType .__qualname__ } '
668+ check_format (f'type: { fullname_alt } ' ,
669+ b'type: %#T' , py_object (obj ))
670+
671+ # test %N
672+ check_format ('type: str' ,
673+ b'type: %N' , py_object (str ))
674+ check_format (f'type: st' ,
675+ b'type: %.2N' , py_object (str ))
676+ check_format (f'type: str' ,
677+ b'type: %10N' , py_object (str ))
678+
679+ check_format (f'type: { fullname } ' ,
680+ b'type: %N' , py_object (type (obj )))
681+ check_format (f'type: { fullname_alt } ' ,
682+ b'type: %#N' , py_object (type (obj )))
683+ with self .assertRaisesRegex (TypeError , "%N argument must be a type" ):
684+ check_format ('type: str' ,
685+ b'type: %N' , py_object ("abc" ))
686+
653687 # test variable width and precision
654688 check_format (' abc' , b'%*s' , c_int (5 ), b'abc' )
655689 check_format ('ab' , b'%.*s' , c_int (2 ), b'abc' )
0 commit comments