@@ -583,76 +583,59 @@ parse_internal_render_format_spec(PyObject *obj,
583583 we're doing (int, float, string). */
584584
585585 switch (format -> type ) {
586- case 'b' :
587- case 'c' :
588- case 'd' :
589586 case 'e' :
590587 case 'E' :
591588 case 'f' :
592589 case 'F' :
593590 case 'g' :
594591 case 'G' :
592+ case '%' :
593+ case '\0' :
594+ break ;
595+ case 'd' :
596+ if (format -> frac_thousands_separator != LT_NO_LOCALE ) {
597+ invalid_fraction_separator_type (format -> frac_thousands_separator ,
598+ format -> type );
599+ return 0 ;
600+ }
601+ break ;
602+ case 'c' :
603+ case 's' :
595604 case 'n' :
605+ if (format -> thousands_separators != LT_NO_LOCALE ) {
606+ invalid_thousands_separator_type (format -> thousands_separators ,
607+ format -> type );
608+ return 0 ;
609+ }
610+ if (format -> frac_thousands_separator != LT_NO_LOCALE ) {
611+ invalid_fraction_separator_type (format -> frac_thousands_separator ,
612+ format -> type );
613+ return 0 ;
614+ }
615+ break ;
616+ case 'b' :
596617 case 'o' :
597- case 's' :
598618 case 'x' :
599619 case 'X' :
600- case '%' :
601- case '\0' :
602- /* These are all valid types. */
603- break ;
604- default :
605- unknown_presentation_type (format -> type , Py_TYPE (obj )-> tp_name );
606- return 0 ;
607- }
608-
609- if (format -> thousands_separators != LT_NO_LOCALE ) {
610- switch (format -> type ) {
611- case 'd' :
612- case 'e' :
613- case 'f' :
614- case 'g' :
615- case 'E' :
616- case 'G' :
617- case '%' :
618- case 'F' :
619- case '\0' :
620- /* These are allowed. See PEP 378.*/
621- break ;
622- case 'b' :
623- case 'o' :
624- case 'x' :
625- case 'X' :
626- /* Underscores are allowed in bin/oct/hex. See PEP 515. */
627- if (format -> thousands_separators == LT_UNDERSCORE_LOCALE ) {
628- /* Every four digits, not every three, in bin/oct/hex. */
629- format -> thousands_separators = LT_UNDER_FOUR_LOCALE ;
630- break ;
631- }
632- _Py_FALLTHROUGH ;
633- default :
620+ /* Underscores are allowed in bin/oct/hex. See PEP 515. */
621+ if (format -> thousands_separators == LT_UNDERSCORE_LOCALE ) {
622+ /* Every four digits, not every three, in bin/oct/hex. */
623+ format -> thousands_separators = LT_UNDER_FOUR_LOCALE ;
624+ }
625+ else if (format -> thousands_separators != LT_NO_LOCALE ) {
634626 invalid_thousands_separator_type (format -> thousands_separators ,
635627 format -> type );
636628 return 0 ;
637629 }
638- }
639-
640- if (format -> frac_thousands_separator != LT_NO_LOCALE ) {
641- switch (format -> type ) {
642- case 'e' :
643- case 'f' :
644- case 'g' :
645- case 'E' :
646- case 'G' :
647- case '%' :
648- case 'F' :
649- case '\0' :
650- break ;
651- default :
630+ if (format -> frac_thousands_separator != LT_NO_LOCALE ) {
652631 invalid_fraction_separator_type (format -> frac_thousands_separator ,
653632 format -> type );
654633 return 0 ;
655634 }
635+ break ;
636+ default :
637+ unknown_presentation_type (format -> type , Py_TYPE (obj )-> tp_name );
638+ return 0 ;
656639 }
657640
658641 assert (format -> align <= 127 );
0 commit comments