Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 84444:e3ec8b176a80
Issue #15767: Revert 3a50025f1900 for ModuleNotFoundError
| author | Brett Cannon <brett@python.org> |
|---|---|
| date | Thu, 04 Jul 2013 17:48:16 -0400 |
| parents | 3a50025f1900 |
| children | 2f7c4df5cc46 |
comparison
equal
deleted
inserted
replaced
| 84443:0e4e062751fa | 84444:e3ec8b176a80 |
|---|---|
| 617 return result; | 617 return result; |
| 618 } | 618 } |
| 619 #endif /* MS_WINDOWS */ | 619 #endif /* MS_WINDOWS */ |
| 620 | 620 |
| 621 PyObject * | 621 PyObject * |
| 622 PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg, | 622 PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) |
| 623 PyObject *name, PyObject *path) | 623 { |
| 624 { | |
| 625 int issubclass; | |
| 626 PyObject *args, *kwargs, *error; | 624 PyObject *args, *kwargs, *error; |
| 627 | 625 |
| 628 issubclass = PyObject_IsSubclass(exception, PyExc_ImportError); | 626 if (msg == NULL) |
| 629 if (issubclass < 0) { | |
| 630 return NULL; | 627 return NULL; |
| 631 } | |
| 632 else if (!issubclass) { | |
| 633 PyErr_SetString(PyExc_TypeError, "expected a subclass of ImportError"); | |
| 634 return NULL; | |
| 635 } | |
| 636 | |
| 637 if (msg == NULL) { | |
| 638 PyErr_SetString(PyExc_TypeError, "expected a message argument"); | |
| 639 return NULL; | |
| 640 } | |
| 641 | 628 |
| 642 args = PyTuple_New(1); | 629 args = PyTuple_New(1); |
| 643 if (args == NULL) | 630 if (args == NULL) |
| 644 return NULL; | 631 return NULL; |
| 645 | 632 |
| 660 Py_INCREF(msg); | 647 Py_INCREF(msg); |
| 661 PyTuple_SET_ITEM(args, 0, msg); | 648 PyTuple_SET_ITEM(args, 0, msg); |
| 662 PyDict_SetItemString(kwargs, "name", name); | 649 PyDict_SetItemString(kwargs, "name", name); |
| 663 PyDict_SetItemString(kwargs, "path", path); | 650 PyDict_SetItemString(kwargs, "path", path); |
| 664 | 651 |
| 665 error = PyObject_Call(exception, args, kwargs); | 652 error = PyObject_Call(PyExc_ImportError, args, kwargs); |
| 666 if (error != NULL) { | 653 if (error != NULL) { |
| 667 PyErr_SetObject((PyObject *)Py_TYPE(error), error); | 654 PyErr_SetObject((PyObject *)Py_TYPE(error), error); |
| 668 Py_DECREF(error); | 655 Py_DECREF(error); |
| 669 } | 656 } |
| 670 | 657 |
| 671 Py_DECREF(args); | 658 Py_DECREF(args); |
| 672 Py_DECREF(kwargs); | 659 Py_DECREF(kwargs); |
| 673 | 660 |
| 674 return NULL; | 661 return NULL; |
| 675 } | |
| 676 | |
| 677 PyObject * | |
| 678 PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) | |
| 679 { | |
| 680 return PyErr_SetImportErrorSubclass(PyExc_ImportError, msg, name, path); | |
| 681 } | 662 } |
| 682 | 663 |
| 683 void | 664 void |
| 684 _PyErr_BadInternalCall(const char *filename, int lineno) | 665 _PyErr_BadInternalCall(const char *filename, int lineno) |
| 685 { | 666 { |
