mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Upgrade None assignment SyntaxWarning to a SyntaxError.
This commit is contained in:
		
							parent
							
								
									910d8f1e89
								
							
						
					
					
						commit
						11a70c79b9
					
				
					 2 changed files with 21 additions and 7 deletions
				
			
		|  | @ -138,6 +138,21 @@ def test_sequence_unpacking_error(self): | |||
|         self.assertEqual(i, 1) | ||||
|         self.assertEqual(j, -1) | ||||
| 
 | ||||
|     def test_none_assignment(self): | ||||
|         stmts = [ | ||||
|             'None = 0', | ||||
|             'None += 0', | ||||
|             '__builtins__.None = 0', | ||||
|             'def None(): pass', | ||||
|             'class None: pass', | ||||
|             '(a, None) = 0, 0', | ||||
|             'for None in range(10): pass', | ||||
|             'def f(None): pass', | ||||
|         ] | ||||
|         for stmt in stmts: | ||||
|             stmt += "\n" | ||||
|             self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'single') | ||||
|             self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec') | ||||
| 
 | ||||
| def test_main(): | ||||
|     test_support.run_unittest(TestSpecifics) | ||||
|  |  | |||
|  | @ -1227,11 +1227,9 @@ none_assignment_check(struct compiling *c, char *name, int assigning) | |||
| 			msg = "assignment to None"; | ||||
| 		else | ||||
| 			msg = "deleting None"; | ||||
| 		if (issue_warning(msg, c->c_filename, c->c_lineno) < 0) { | ||||
| 			c->c_errors++; | ||||
| 		com_error(c, PyExc_SyntaxError, msg); | ||||
| 		return -1; | ||||
| 	} | ||||
| 	} | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
|  | @ -1247,7 +1245,6 @@ com_addop_varname(struct compiling *c, int kind, char *name) | |||
| 	if (kind != VAR_LOAD && | ||||
| 	    none_assignment_check(c, name, kind == VAR_STORE)) | ||||
| 	{ | ||||
| 		c->c_errors++; | ||||
| 		i = 255; | ||||
| 		goto done; | ||||
| 	} | ||||
|  | @ -5483,7 +5480,9 @@ symtable_add_def(struct symtable *st, char *name, int flag) | |||
| 	if ((flag & DEF_PARAM) && !(flag & DEF_INTUPLE) && | ||||
| 	    *name == 'N' && strcmp(name, "None") == 0) | ||||
| 	{ | ||||
| 		if (symtable_warn(st, "argument named None")) | ||||
| 		PyErr_SetString(PyExc_SyntaxError,  | ||||
| 			"Invalid syntax.  Assignment to None."); | ||||
| 		symtable_error(st, 0); | ||||
| 		return  -1; | ||||
| 	} | ||||
| 	if (_Py_Mangle(st->st_private, name, buffer, sizeof(buffer))) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Raymond Hettinger
						Raymond Hettinger