@@ -618,36 +618,38 @@ SimpleExtendsException(PyExc_BaseException, KeyboardInterrupt,
618618static int
619619ImportError_init (PyImportErrorObject * self , PyObject * args , PyObject * kwds )
620620{
621+ static char * kwlist [] = {"name" , "path" , 0 };
622+ PyObject * empty_tuple ;
621623 PyObject * msg = NULL ;
622624 PyObject * name = NULL ;
623625 PyObject * path = NULL ;
624626
625- /* Macro replacement doesn't allow ## to start the first line of a macro,
626- so we move the assignment and NULL check into the if-statement. */
627- #define GET_KWD (kwd ) { \
628- kwd = PyDict_GetItemString(kwds, #kwd); \
629- if (kwd) { \
630- Py_INCREF(kwd); \
631- Py_XSETREF(self->kwd, kwd); \
632- if (PyDict_DelItemString(kwds, #kwd)) \
633- return -1; \
634- } \
635- }
636-
637- if (kwds ) {
638- GET_KWD (name );
639- GET_KWD (path );
640- }
627+ if (BaseException_init ((PyBaseExceptionObject * )self , args , NULL ) == -1 )
628+ return -1 ;
641629
642- if (BaseException_init ((PyBaseExceptionObject * )self , args , kwds ) == -1 )
630+ empty_tuple = PyTuple_New (0 );
631+ if (!empty_tuple )
643632 return -1 ;
644- if (PyTuple_GET_SIZE ( args ) != 1 )
645- return 0 ;
646- if (! PyArg_UnpackTuple ( args , "ImportError" , 1 , 1 , & msg ))
633+ if (! PyArg_ParseTupleAndKeywords ( empty_tuple , kwds , "|$OO:ImportError" , kwlist ,
634+ & name , & path )) {
635+ Py_DECREF ( empty_tuple );
647636 return -1 ;
637+ }
638+ Py_DECREF (empty_tuple );
648639
649- Py_INCREF (msg );
650- Py_XSETREF (self -> msg , msg );
640+ if (name ) {
641+ Py_INCREF (name );
642+ Py_XSETREF (self -> name , name );
643+ }
644+ if (path ) {
645+ Py_INCREF (path );
646+ Py_XSETREF (self -> path , path );
647+ }
648+ if (PyTuple_GET_SIZE (args ) == 1 ) {
649+ msg = PyTuple_GET_ITEM (args , 0 );
650+ Py_INCREF (msg );
651+ Py_XSETREF (self -> msg , msg );
652+ }
651653
652654 return 0 ;
653655}
0 commit comments