mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 11:49:12 +00:00 
			
		
		
		
	Make error messages clearer for illegal combinations of nested
functions and import */exec.
This commit is contained in:
		
							parent
							
								
									6e9c0baa65
								
							
						
					
					
						commit
						280e6bd742
					
				
					 1 changed files with 36 additions and 15 deletions
				
			
		| 
						 | 
					@ -4191,30 +4191,51 @@ symtable_check_unoptimized(struct compiling *c,
 | 
				
			||||||
	      || (ste->ste_nested && si->si_nimplicit)))
 | 
						      || (ste->ste_nested && si->si_nimplicit)))
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ILLEGAL_CONTAINS "contains a nested function with free variables"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ILLEGAL_IS "is a nested function"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define ILLEGAL_IMPORT_STAR \
 | 
					#define ILLEGAL_IMPORT_STAR \
 | 
				
			||||||
"import * is not allowed in function '%.100s' " \
 | 
					"import * is not allowed in function '%.100s' because it %s"
 | 
				
			||||||
"because it contains a nested function with free variables"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define ILLEGAL_BARE_EXEC \
 | 
					#define ILLEGAL_BARE_EXEC \
 | 
				
			||||||
"unqualified exec is not allowed in function '%.100s' " \
 | 
					"unqualified exec is not allowed in function '%.100s' it %s"
 | 
				
			||||||
"because it contains a nested function with free variables"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define ILLEGAL_EXEC_AND_IMPORT_STAR \
 | 
					#define ILLEGAL_EXEC_AND_IMPORT_STAR \
 | 
				
			||||||
"function '%.100s' uses import * and bare exec, which are illegal" \
 | 
					"function '%.100s' uses import * and bare exec, which are illegal" \
 | 
				
			||||||
"because it contains a nested function with free variables"
 | 
					"because it %s"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* XXX perhaps the linenos for these opt-breaking statements
 | 
						/* XXX perhaps the linenos for these opt-breaking statements
 | 
				
			||||||
	   should be stored so the exception can point to them. */
 | 
						   should be stored so the exception can point to them. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (ste->ste_child_free) {
 | 
				
			||||||
		if (ste->ste_optimized == OPT_IMPORT_STAR)
 | 
							if (ste->ste_optimized == OPT_IMPORT_STAR)
 | 
				
			||||||
			sprintf(buf, ILLEGAL_IMPORT_STAR, 
 | 
								sprintf(buf, ILLEGAL_IMPORT_STAR, 
 | 
				
			||||||
			PyString_AS_STRING(ste->ste_name));
 | 
									PyString_AS_STRING(ste->ste_name),
 | 
				
			||||||
 | 
									ILLEGAL_CONTAINS);
 | 
				
			||||||
		else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC))
 | 
							else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC))
 | 
				
			||||||
			sprintf(buf, ILLEGAL_BARE_EXEC,
 | 
								sprintf(buf, ILLEGAL_BARE_EXEC,
 | 
				
			||||||
			PyString_AS_STRING(ste->ste_name));
 | 
									PyString_AS_STRING(ste->ste_name),
 | 
				
			||||||
 | 
									ILLEGAL_CONTAINS);
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
			sprintf(buf, ILLEGAL_EXEC_AND_IMPORT_STAR,
 | 
								sprintf(buf, ILLEGAL_EXEC_AND_IMPORT_STAR,
 | 
				
			||||||
			PyString_AS_STRING(ste->ste_name));
 | 
									PyString_AS_STRING(ste->ste_name),
 | 
				
			||||||
 | 
									ILLEGAL_CONTAINS);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							if (ste->ste_optimized == OPT_IMPORT_STAR)
 | 
				
			||||||
 | 
								sprintf(buf, ILLEGAL_IMPORT_STAR, 
 | 
				
			||||||
 | 
									PyString_AS_STRING(ste->ste_name),
 | 
				
			||||||
 | 
									ILLEGAL_IS);
 | 
				
			||||||
 | 
							else if (ste->ste_optimized == (OPT_BARE_EXEC | OPT_EXEC))
 | 
				
			||||||
 | 
								sprintf(buf, ILLEGAL_BARE_EXEC,
 | 
				
			||||||
 | 
									PyString_AS_STRING(ste->ste_name),
 | 
				
			||||||
 | 
									ILLEGAL_IS);
 | 
				
			||||||
 | 
							else {
 | 
				
			||||||
 | 
								sprintf(buf, ILLEGAL_EXEC_AND_IMPORT_STAR,
 | 
				
			||||||
 | 
									PyString_AS_STRING(ste->ste_name),
 | 
				
			||||||
 | 
									ILLEGAL_IS);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (c->c_symtable->st_nested_scopes) {
 | 
						if (c->c_symtable->st_nested_scopes) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue