mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Make it illegal to assign to __debug__ as per Guido's request.
This commit is contained in:
		
							parent
							
								
									e280c06d59
								
							
						
					
					
						commit
						897b82123d
					
				
					 1 changed files with 12 additions and 1 deletions
				
			
		|  | @ -66,6 +66,9 @@ int Py_OptimizeFlag = 0; | ||||||
| #define LATE_FUTURE \ | #define LATE_FUTURE \ | ||||||
| "from __future__ imports must occur at the beginning of the file" | "from __future__ imports must occur at the beginning of the file" | ||||||
| 
 | 
 | ||||||
|  | #define ASSIGN_DEBUG \ | ||||||
|  | "can not assign to __debug__" | ||||||
|  | 
 | ||||||
| #define MANGLE_LEN 256 | #define MANGLE_LEN 256 | ||||||
| 
 | 
 | ||||||
| #define OFF(x) offsetof(PyCodeObject, x) | #define OFF(x) offsetof(PyCodeObject, x) | ||||||
|  | @ -5181,8 +5184,16 @@ symtable_assign(struct symtable *st, node *n, int flag) | ||||||
| 		if (TYPE(tmp) == LPAR || TYPE(tmp) == LSQB) { | 		if (TYPE(tmp) == LPAR || TYPE(tmp) == LSQB) { | ||||||
| 			n = CHILD(n, 1); | 			n = CHILD(n, 1); | ||||||
| 			goto loop; | 			goto loop; | ||||||
| 		} else if (TYPE(tmp) == NAME) | 		} else if (TYPE(tmp) == NAME) { | ||||||
|  | 			if (strcmp(STR(tmp), "__debug__") == 0) { | ||||||
|  | 				PyErr_SetString(PyExc_SyntaxError, | ||||||
|  | 						ASSIGN_DEBUG); | ||||||
|  |  				PyErr_SyntaxLocation(st->st_filename, | ||||||
|  | 						   n->n_lineno); | ||||||
|  | 				st->st_errors++; | ||||||
|  | 			} | ||||||
| 			symtable_add_def(st, STR(tmp), DEF_LOCAL | flag); | 			symtable_add_def(st, STR(tmp), DEF_LOCAL | flag); | ||||||
|  | 		} | ||||||
| 		return; | 		return; | ||||||
| 	case dotted_as_name: | 	case dotted_as_name: | ||||||
| 		if (NCH(n) == 3) | 		if (NCH(n) == 3) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jeremy Hylton
						Jeremy Hylton