@@ -574,6 +574,7 @@ block_pop(struct compiling *c, int type)
574574
575575/* Prototype forward declarations */
576576
577+ static int issue_warning (char * , char * , int );
577578static int com_init (struct compiling * , char * );
578579static void com_free (struct compiling * );
579580static void com_push (struct compiling * , int );
@@ -988,6 +989,23 @@ com_lookup_arg(PyObject *dict, PyObject *name)
988989 return PyInt_AS_LONG (v );
989990}
990991
992+ static int
993+ none_assignment_check (struct compiling * c , char * name , int assigning )
994+ {
995+ if (name [0 ] == 'N' && strcmp (name , "None" ) == 0 ) {
996+ char * msg ;
997+ if (assigning )
998+ msg = "assigment to None" ;
999+ else
1000+ msg = "deleting None" ;
1001+ if (issue_warning (msg , c -> c_filename , c -> c_lineno ) < 0 ) {
1002+ c -> c_errors ++ ;
1003+ return -1 ;
1004+ }
1005+ }
1006+ return 0 ;
1007+ }
1008+
9911009static void
9921010com_addop_varname (struct compiling * c , int kind , char * name )
9931011{
@@ -997,6 +1015,13 @@ com_addop_varname(struct compiling *c, int kind, char *name)
9971015 int op = STOP_CODE ;
9981016 char buffer [MANGLE_LEN ];
9991017
1018+ if (kind != VAR_LOAD &&
1019+ none_assignment_check (c , name , kind == VAR_STORE ))
1020+ {
1021+ c -> c_errors ++ ;
1022+ i = 255 ;
1023+ goto done ;
1024+ }
10001025 if (_Py_Mangle (c -> c_private , name , buffer , sizeof (buffer )))
10011026 name = buffer ;
10021027 if (name == NULL || (v = PyString_InternFromString (name )) == NULL ) {
@@ -2489,6 +2514,8 @@ com_augassign_attr(struct compiling *c, node *n, int opcode, node *augn)
24892514static void
24902515com_assign_attr (struct compiling * c , node * n , int assigning )
24912516{
2517+ if (none_assignment_check (c , STR (n ), assigning ))
2518+ return ;
24922519 com_addopname (c , assigning ? STORE_ATTR : DELETE_ATTR , n );
24932520 com_pop (c , assigning ? 2 : 1 );
24942521}
0 commit comments