mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Move test.test_support.catch_warning() to the warnings module, rename it
catch_warnings(), and clean up the API. While expanding the test suite, a bug was found where a warning about the 'line' argument to showwarning() was not letting functions with '*args' go without a warning. Closes issue 3602. Code review by Benjamin Peterson.
This commit is contained in:
		
							parent
							
								
									86533776c2
								
							
						
					
					
						commit
						1eaf0742d8
					
				
					 11 changed files with 208 additions and 126 deletions
				
			
		|  | @ -1,4 +1,5 @@ | |||
| #include "Python.h" | ||||
| #include "code.h"  /* For DeprecationWarning about adding 'line'. */ | ||||
| #include "frameobject.h" | ||||
| 
 | ||||
| #define MODULE_NAME "_warnings" | ||||
|  | @ -416,11 +417,16 @@ warn_explicit(PyObject *category, PyObject *message, | |||
|                 /* A proper implementation of warnings.showwarning() should
 | ||||
|                     have at least two default arguments. */ | ||||
|                 if ((defaults == NULL) || (PyTuple_Size(defaults) < 2)) { | ||||
|                     if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1) < 0) { | ||||
|                         Py_DECREF(show_fxn); | ||||
|                         goto cleanup; | ||||
| 	            PyCodeObject *code = (PyCodeObject *) | ||||
| 						PyFunction_GetCode(check_fxn); | ||||
| 		    if (!(code->co_flags & CO_VARARGS)) { | ||||
| 		        if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1) < | ||||
| 				0) { | ||||
|                             Py_DECREF(show_fxn); | ||||
|                             goto cleanup; | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
| 		} | ||||
|                 res = PyObject_CallFunctionObjArgs(show_fxn, message, category, | ||||
|                                                     filename, lineno_obj, | ||||
|                                                     NULL); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brett Cannon
						Brett Cannon