mirror of
				https://github.com/python/cpython.git
				synced 2025-10-29 20:51:26 +00:00 
			
		
		
		
	SF bug #1014215: Unspecific errors with metaclass
High level error message was stomping useful detailed messages from lower level routines. The new approach is to augment string error messages returned by the low level routines. The provides both high and low level information. If the exception value is not a string, no changes are made. To see the improved messages in action, type: import random class R(random): pass class B(bool): pass
This commit is contained in:
		
							parent
							
								
									6543b45b0c
								
							
						
					
					
						commit
						cfc3192677
					
				
					 1 changed files with 16 additions and 4 deletions
				
			
		|  | @ -4086,10 +4086,22 @@ build_class(PyObject *methods, PyObject *bases, PyObject *name) | ||||||
| 		/* A type error here likely means that the user passed 
 | 		/* A type error here likely means that the user passed 
 | ||||||
| 		   in a base that was not a class (such the random module | 		   in a base that was not a class (such the random module | ||||||
| 		   instead of the random.random type).  Help them out with | 		   instead of the random.random type).  Help them out with | ||||||
| 		   a more informative error message */ | 		   by augmenting the error message with more information.*/ | ||||||
| 		PyErr_SetString(PyExc_TypeError, | 
 | ||||||
| 			"Error when calling the metaclass.\n" \ | 		PyObject *ptype, *pvalue, *ptraceback; | ||||||
| 			"Make sure the base arguments are valid."); | 
 | ||||||
|  | 		PyErr_Fetch(&ptype, &pvalue, &ptraceback); | ||||||
|  | 		if (PyString_Check(pvalue)) { | ||||||
|  | 			PyObject *newmsg; | ||||||
|  | 			newmsg = PyString_FromFormat( | ||||||
|  | 				"Error when calling the metaclass bases\n    %s", | ||||||
|  | 				PyString_AS_STRING(pvalue)); | ||||||
|  | 			if (newmsg != NULL) { | ||||||
|  | 				Py_DECREF(pvalue); | ||||||
|  | 				pvalue = newmsg; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		PyErr_Restore(ptype, pvalue, ptraceback); | ||||||
| 	} | 	} | ||||||
| 	return result; | 	return result; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Raymond Hettinger
						Raymond Hettinger