mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Do the check for no keyword arguments in __init__ so that
subclasses of Exception can be supplied keyword args
This commit is contained in:
		
							parent
							
								
									5b72cd321d
								
							
						
					
					
						commit
						b0432bc032
					
				
					 2 changed files with 4 additions and 4 deletions
				
			
		| 
						 | 
					@ -299,7 +299,7 @@ def test_capi2():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
try:
 | 
					try:
 | 
				
			||||||
    BaseException(a=1)
 | 
					    BaseException(a=1)
 | 
				
			||||||
except TypeErrror:
 | 
					except TypeError:
 | 
				
			||||||
    pass
 | 
					    pass
 | 
				
			||||||
else:
 | 
					else:
 | 
				
			||||||
    raise TestFailed("BaseException shouldn't take keyword args")
 | 
					    raise TestFailed("BaseException shouldn't take keyword args")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,9 +32,6 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PyBaseExceptionObject *self;
 | 
					    PyBaseExceptionObject *self;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!_PyArg_NoKeywords("BaseException", kwds))
 | 
					 | 
				
			||||||
        return NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    self = (PyBaseExceptionObject *)type->tp_alloc(type, 0);
 | 
					    self = (PyBaseExceptionObject *)type->tp_alloc(type, 0);
 | 
				
			||||||
    /* the dict is created on the fly in PyObject_GenericSetAttr */
 | 
					    /* the dict is created on the fly in PyObject_GenericSetAttr */
 | 
				
			||||||
    self->message = self->dict = NULL;
 | 
					    self->message = self->dict = NULL;
 | 
				
			||||||
| 
						 | 
					@ -57,6 +54,9 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 | 
				
			||||||
static int
 | 
					static int
 | 
				
			||||||
BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
 | 
					BaseException_init(PyBaseExceptionObject *self, PyObject *args, PyObject *kwds)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    if (!_PyArg_NoKeywords(self->ob_type->tp_name, kwds))
 | 
				
			||||||
 | 
					        return -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Py_DECREF(self->args);
 | 
					    Py_DECREF(self->args);
 | 
				
			||||||
    self->args = args;
 | 
					    self->args = args;
 | 
				
			||||||
    Py_INCREF(self->args);
 | 
					    Py_INCREF(self->args);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue