This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ImportError.__init__ doesn't reset not specified exception attributes
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: brett.cannon, eric.snow, ncoghlan, python-dev, serhiy.storchaka
Priority: low Keywords: patch

Created on 2016-09-27 18:02 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
importerror-reset-attributes.patch serhiy.storchaka, 2016-09-27 20:47 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (7)
msg277533 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-27 18:02
ImportError.__init__ sets only specified attributes ("msg", "name" or "path"), and left not explicitly specified attributes unchanged.

>>> err = ImportError('test', name='name')
>>> err.args, err.msg, err.name, err.path
(('test',), 'test', 'name', None)
>>> err.__init__(path='path')
>>> err.args, err.msg, err.name, err.path
((), 'test', 'name', 'path')

In above example err.__init__(path='path') sets attributes "args" and "path", but not "msg" and "name".

I'm not sure whether can this be considered as a bug.
msg277537 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-09-27 18:31
I think it's a bug, but a low priority one.
msg277547 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-27 20:47
Here is a simple patch.

But I'm not sure that this is a bug.
msg277554 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-09-27 21:58
Patch LGTM.
msg277555 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-09-27 21:58
And I say don't worry about backporting.
msg277581 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-28 04:54
Thanks Brett.
msg277710 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-29 17:48
New changeset dcb39d3ba67a by Serhiy Storchaka in branch 'default':
Issue #28289: ImportError.__init__ now resets not specified attributes.
https://hg.python.org/cpython/rev/dcb39d3ba67a
History
Date User Action Args
2022-04-11 14:58:37adminsetgithub: 72476
2017-03-31 16:36:31dstufftsetpull_requests: + pull_request1040
2016-09-29 17:48:08python-devsetnosy: + python-dev
messages: + msg277710
2016-09-28 04:54:25serhiy.storchakasetstatus: open -> closed
versions: - Python 3.5, Python 3.6
messages: + msg277581

resolution: fixed
stage: patch review -> resolved
2016-09-27 21:58:34brett.cannonsetmessages: + msg277555
2016-09-27 21:58:02brett.cannonsetassignee: serhiy.storchaka
messages: + msg277554
2016-09-27 20:47:12serhiy.storchakasetfiles: + importerror-reset-attributes.patch
keywords: + patch
messages: + msg277547

stage: patch review
2016-09-27 18:31:02brett.cannonsetpriority: normal -> low

messages: + msg277537
2016-09-27 18:02:52serhiy.storchakacreate