Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-74185: repr() of ImportError now contains attributes name and path#136770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
Yoav11 wants to merge28 commits intopython:mainChoose a base branch fromYoav11:importerror-repr
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+126 −6
Open
Changes from1 commit
Commits
Show all changes
28 commits Select commitHold shift + click to select a range
cb764d9
bpo-29999: repr() of ImportError now contains attributes name and path.
serhiy-storchakadb41c7d
Use GitHub Actions version of Bedevere
arhadthedev1caeb91
Add the news entry back
arhadthedev7f29270
Remove an accidentally included untracked file
arhadthedevc80e056
first commit
ynir3126be20
add test_ModuleNotFoundError_repr_with_failed_import
ynir34a97f5c
add test_ModuleNotFoundError_repr_with_failed_import
ynir3852da8c
add blurb
ynir36ab7362
add noqa:F401
ynir312c2293
remove whitespace
ynir3a53da37
fix trailing-whitespace
ynir35b6d626
use ComplexExtendsException
ynir3951e0a1
return to non-macro style
ynir38fbfd18
use modern field initializers
ynir3458bcd0
remove un-necessary casts
ynir3fa2f884
use PyUnicodeWriter
ynir335a6a29
fix trailing whitespace
ynir36e416c6
reduce nesting
ynir3aa75f6a
use PyUnicdodeWriter_Format and if statement braces
ynir38b5e4ed
indentation
ynir328545e5
move decref
ynir34f63193
check baseException_repr failure, add 3.15rst
ynir362a479b
Merge branch 'main' into importerror-repr
Yoav1125f3d42
fix chr c input
ynir3a45ed75
move tests, edit rst wording
ynir369e7305
Merge branch 'main' into importerror-repr
Yoav119c09cd0
edit blurb
ynir3ca0e2a4
edit blurb
ynir3File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
bpo-29999: repr() of ImportError now contains attributes name and path.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commitcb764d9dd9d6ad1e10ad89150c3634e1b567e1f9
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2595,6 +2595,36 @@ def after_with(): | ||
with ExitFails(): | ||
1/0 | ||
self.lineno_after_raise(after_with, 1, 1) | ||
def test_repr(self): | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
exc = ImportError() | ||
self.assertEqual(repr(exc), "ImportError()") | ||
exc = ImportError('test') | ||
self.assertEqual(repr(exc), "ImportError('test')") | ||
exc = ImportError('test', 'case') | ||
self.assertEqual(repr(exc), "ImportError('test', 'case')") | ||
exc = ImportError(name='somemodule') | ||
self.assertEqual(repr(exc), "ImportError(name='somemodule')") | ||
exc = ImportError('test', name='somemodule') | ||
self.assertEqual(repr(exc), "ImportError('test', name='somemodule')") | ||
exc = ImportError(path='somepath') | ||
self.assertEqual(repr(exc), "ImportError(path='somepath')") | ||
exc = ImportError('test', path='somepath') | ||
self.assertEqual(repr(exc), "ImportError('test', path='somepath')") | ||
exc = ImportError(name='somename', path='somepath') | ||
self.assertEqual(repr(exc), | ||
"ImportError(name='somename', path='somepath')") | ||
exc = ImportError('test', name='somename', path='somepath') | ||
self.assertEqual(repr(exc), | ||
"ImportError('test', name='somename', path='somepath')") | ||
if __name__ == '__main__': | ||
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1864,6 +1864,30 @@ ImportError_reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) | ||
return res; | ||
} | ||
static PyObject * | ||
ImportError_repr(PyImportErrorObject *self) | ||
{ | ||
int hasargs = PyTuple_GET_SIZE(((PyBaseExceptionObject *)self)->args) != 0; | ||
PyObject *r = BaseException_repr((PyBaseExceptionObject *)self); | ||
if (r && (self->name || self->path)) { | ||
/* remove ')' */ | ||
Py_SETREF(r, PyUnicode_Substring(r, 0, PyUnicode_GET_LENGTH(r) - 1)); | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if (r && self->name) { | ||
Py_SETREF(r, PyUnicode_FromFormat("%U%sname=%R", | ||
r, hasargs ? ", " : "", self->name)); | ||
hasargs = 1; | ||
} | ||
if (r && self->path) { | ||
Py_SETREF(r, PyUnicode_FromFormat("%U%spath=%R", | ||
r, hasargs ? ", " : "", self->path)); | ||
} | ||
if (r) { | ||
Py_SETREF(r, PyUnicode_FromFormat("%U)", r)); | ||
} | ||
} | ||
return r; | ||
} | ||
static PyMemberDef ImportError_members[] = { | ||
{"msg", _Py_T_OBJECT, offsetof(PyImportErrorObject, msg), 0, | ||
PyDoc_STR("exception message")}, | ||
@@ -1881,12 +1905,23 @@ static PyMethodDef ImportError_methods[] = { | ||
{NULL} | ||
}; | ||
static PyTypeObject _PyExc_ImportError = { | ||
PyVarObject_HEAD_INIT(NULL, 0) | ||
"ImportError", | ||
sizeof(PyImportErrorObject), 0, | ||
(destructor)ImportError_dealloc, 0, 0, 0, 0, | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
(reprfunc)ImportError_repr, 0, 0, 0, 0, 0, | ||
(reprfunc)ImportError_str, 0, 0, 0, | ||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, | ||
PyDoc_STR("Import can't find module, or can't find name in " | ||
"module."), | ||
(traverseproc)ImportError_traverse, | ||
(inquiry)ImportError_clear, 0, 0, 0, 0, ImportError_methods, | ||
ImportError_members, 0, &_PyExc_Exception, | ||
0, 0, 0, offsetof(PyImportErrorObject, dict), | ||
(initproc)ImportError_init, | ||
}; | ||
PyObject *PyExc_ImportError = (PyObject *)&_PyExc_ImportError; | ||
/* | ||
* ModuleNotFoundError extends ImportError | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.