Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 76272:6825fd9b00ed
Issue #1559549: Add 'name' and 'path' attributes to ImportError.
Currently import does not use these attributes as they are planned
for use by importlib (which will be another commit).
Thanks to Filip GruszczyĆski for the initial patch and Brian Curtin
for refining it.
| author | Brett Cannon <brett@python.org> |
|---|---|
| date | Thu, 12 Apr 2012 20:24:54 -0400 |
| parents | 07802351ccad |
| children | 7a32b9380ffd |
comparison
equal
deleted
inserted
replaced
| 76271:e5b30d4b0647 | 76272:6825fd9b00ed |
|---|---|
| 583 Py_XDECREF(name); | 583 Py_XDECREF(name); |
| 584 return result; | 584 return result; |
| 585 } | 585 } |
| 586 #endif /* MS_WINDOWS */ | 586 #endif /* MS_WINDOWS */ |
| 587 | 587 |
| 588 PyObject * | |
| 589 PyErr_SetExcWithArgsKwargs(PyObject *exc, PyObject *args, PyObject *kwargs) | |
| 590 { | |
| 591 PyObject *val; | |
| 592 | |
| 593 /* args must at least be an empty tuple */ | |
| 594 if (args == NULL) | |
| 595 args = PyTuple_New(0); | |
| 596 | |
| 597 val = PyObject_Call(exc, args, kwargs); | |
| 598 if (val != NULL) { | |
| 599 PyErr_SetObject((PyObject *) Py_TYPE(val), val); | |
| 600 Py_DECREF(val); | |
| 601 } | |
| 602 | |
| 603 return NULL; | |
| 604 } | |
| 605 | |
| 606 PyObject * | |
| 607 PyErr_SetFromImportErrorWithNameAndPath(PyObject *msg, | |
| 608 PyObject *name, PyObject *path) | |
| 609 { | |
| 610 PyObject *args = PyTuple_New(1); | |
| 611 PyObject *kwargs = PyDict_New(); | |
| 612 PyObject *result; | |
| 613 | |
| 614 if (path == NULL) | |
| 615 path = Py_None; | |
| 616 | |
| 617 PyTuple_SetItem(args, 0, msg); | |
| 618 PyDict_SetItemString(kwargs, "name", name); | |
| 619 PyDict_SetItemString(kwargs, "path", path); | |
| 620 | |
| 621 result = PyErr_SetExcWithArgsKwargs(PyExc_ImportError, args, kwargs); | |
| 622 | |
| 623 Py_DECREF(args); | |
| 624 Py_DECREF(kwargs); | |
| 625 | |
| 626 return result; | |
| 627 } | |
| 628 | |
| 629 PyObject * | |
| 630 PyErr_SetFromImportErrorWithName(PyObject *msg, PyObject *name) | |
| 631 { | |
| 632 return PyErr_SetFromImportErrorWithNameAndPath(msg, name, NULL); | |
| 633 } | |
| 634 | |
| 588 void | 635 void |
| 589 _PyErr_BadInternalCall(const char *filename, int lineno) | 636 _PyErr_BadInternalCall(const char *filename, int lineno) |
| 590 { | 637 { |
| 591 PyErr_Format(PyExc_SystemError, | 638 PyErr_Format(PyExc_SystemError, |
| 592 "%s:%d: bad argument to internal function", | 639 "%s:%d: bad argument to internal function", |
