mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 21:51:50 +00:00 
			
		
		
		
	bpo-36052: Raise a SyntaxError when assigning a value to __debug__ with := (GH-11958)
Trying to assign a value to __debug__ using the assignment operator is supposed to fail, but a missing check for forbidden names when setting the context in the ast was preventing this behaviour.
This commit is contained in:
		
							parent
							
								
									ea6207d593
								
							
						
					
					
						commit
						3ad9167305
					
				
					 3 changed files with 7 additions and 1 deletions
				
			
		|  | @ -51,6 +51,10 @@ | ||||||
| Traceback (most recent call last): | Traceback (most recent call last): | ||||||
| SyntaxError: cannot assign to __debug__ | SyntaxError: cannot assign to __debug__ | ||||||
| 
 | 
 | ||||||
|  | >>> (__debug__ := 1) | ||||||
|  | Traceback (most recent call last): | ||||||
|  | SyntaxError: cannot assign to __debug__ | ||||||
|  | 
 | ||||||
| >>> f() = 1 | >>> f() = 1 | ||||||
| Traceback (most recent call last): | Traceback (most recent call last): | ||||||
| SyntaxError: cannot assign to function call | SyntaxError: cannot assign to function call | ||||||
|  |  | ||||||
|  | @ -0,0 +1,2 @@ | ||||||
|  | Raise a :exc:`SyntaxError` when assigning a value to `__debug__` with the | ||||||
|  | Assignment Operator. Contributed by Stéphane Wirtel and Pablo Galindo. | ||||||
|  | @ -1084,7 +1084,7 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n) | ||||||
|                 return 0; |                 return 0; | ||||||
|             break; |             break; | ||||||
|         case Name_kind: |         case Name_kind: | ||||||
|             if (ctx == Store) { |             if (ctx == Store || ctx == NamedStore) { | ||||||
|                 if (forbidden_name(c, e->v.Name.id, n, 0)) |                 if (forbidden_name(c, e->v.Name.id, n, 0)) | ||||||
|                     return 0; /* forbidden_name() calls ast_error() */ |                     return 0; /* forbidden_name() calls ast_error() */ | ||||||
|             } |             } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Stéphane Wirtel
						Stéphane Wirtel