File tree Expand file tree Collapse file tree 2 files changed +22
-12
lines changed Expand file tree Collapse file tree 2 files changed +22
-12
lines changed Original file line number Diff line number Diff line change @@ -822,10 +822,15 @@ def test_constant_as_name(self):
822822                compile (expr , "<test>" , "eval" )
823823
824824    def  test_constant_as_unicode_name (self ):
825-         for  constant  in  b"Tru\xe1 \xb5 \x89 " , b"Fal\xc5 \xbf e" , b"N\xc2 \xba ne" :
825+         constants  =  [
826+             ("True" , b"Tru\xe1 \xb5 \x89 " ),
827+             ("False" , b"Fal\xc5 \xbf e" ),
828+             ("None" , b"N\xc2 \xba ne" ),
829+         ]
830+         for  constant  in  constants :
826831            with  self .assertRaisesRegex (ValueError ,
827-                 "identifier must not be None, True or False after Unicode normalization  \\ (NKFC \\ ) " ):
828-                 ast .parse (constant , mode = "eval" )
832+                 f "identifier field can't represent ' { constant [ 0 ] } ' constant "
833+                 ast .parse (constant [ 1 ] , mode = "eval" )
829834
830835    def  test_precedence_enum (self ):
831836        class  _Precedence (enum .IntEnum ):
Original file line number Diff line number Diff line change @@ -549,15 +549,20 @@ _PyPegen_new_identifier(Parser *p, const char *n)
549549        }
550550        id  =  id2 ;
551551    }
552-     if  (_PyUnicode_EqualToASCIIString (id , "None" )
553-         ||  _PyUnicode_EqualToASCIIString (id , "True" )
554-         ||  _PyUnicode_EqualToASCIIString (id , "False" ))
555-     {
556-         PyErr_SetString (PyExc_ValueError ,
557-                         "identifier must not be None, True or False " 
558-                         "after Unicode normalization (NKFC)" );
559-         Py_DECREF (id );
560-         goto error ;
552+     static  const  char  *  const  forbidden [] =  {
553+         "None" ,
554+         "True" ,
555+         "False" ,
556+         NULL 
557+     };
558+     for  (int  i  =  0 ; forbidden [i ] !=  NULL ; i ++ ) {
559+         if  (_PyUnicode_EqualToASCIIString (id , forbidden [i ])) {
560+             PyErr_Format (PyExc_ValueError ,
561+                          "identifier field can't represent '%s' constant" ,
562+                          forbidden [i ]);
563+             Py_DECREF (id );
564+             goto error ;
565+         }
561566    }
562567    PyInterpreterState  * interp  =  _PyInterpreterState_GET ();
563568    _PyUnicode_InternImmortal (interp , & id );
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments