@@ -612,36 +612,38 @@ SimpleExtendsException(PyExc_BaseException, KeyboardInterrupt,
612612static int
613613ImportError_init (PyImportErrorObject * self , PyObject * args , PyObject * kwds )
614614{
615+ static char * kwlist [] = {"name" , "path" , 0 };
616+ PyObject * empty_tuple ;
615617 PyObject * msg = NULL ;
616618 PyObject * name = NULL ;
617619 PyObject * path = NULL ;
618620
619- /* Macro replacement doesn't allow ## to start the first line of a macro,
620- so we move the assignment and NULL check into the if-statement. */
621- #define GET_KWD (kwd ) { \
622- kwd = PyDict_GetItemString(kwds, #kwd); \
623- if (kwd) { \
624- Py_INCREF(kwd); \
625- Py_XSETREF(self->kwd, kwd); \
626- if (PyDict_DelItemString(kwds, #kwd)) \
627- return -1; \
628- } \
629- }
630-
631- if (kwds ) {
632- GET_KWD (name );
633- GET_KWD (path );
634- }
621+ if (BaseException_init ((PyBaseExceptionObject * )self , args , NULL ) == -1 )
622+ return -1 ;
635623
636- if (BaseException_init ((PyBaseExceptionObject * )self , args , kwds ) == -1 )
624+ empty_tuple = PyTuple_New (0 );
625+ if (!empty_tuple )
637626 return -1 ;
638- if (PyTuple_GET_SIZE ( args ) != 1 )
639- return 0 ;
640- if (! PyArg_UnpackTuple ( args , "ImportError" , 1 , 1 , & msg ))
627+ if (! PyArg_ParseTupleAndKeywords ( empty_tuple , kwds , "|$OO:ImportError" , kwlist ,
628+ & name , & path )) {
629+ Py_DECREF ( empty_tuple );
641630 return -1 ;
631+ }
632+ Py_DECREF (empty_tuple );
642633
643- Py_INCREF (msg );
644- Py_XSETREF (self -> msg , msg );
634+ if (name ) {
635+ Py_INCREF (name );
636+ Py_XSETREF (self -> name , name );
637+ }
638+ if (path ) {
639+ Py_INCREF (path );
640+ Py_XSETREF (self -> path , path );
641+ }
642+ if (PyTuple_GET_SIZE (args ) == 1 ) {
643+ msg = PyTuple_GET_ITEM (args , 0 );
644+ Py_INCREF (msg );
645+ Py_XSETREF (self -> msg , msg );
646+ }
645647
646648 return 0 ;
647649}
0 commit comments