[ python-Feature Requests-1559549 ] ImportError needs attributes for module and file name

SourceForge.net noreply at sourceforge.net
Sat Sep 16 19:52:11 CEST 2006


Feature Requests item #1559549, was opened at 2006-09-15 21:55
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1559549&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Ned Batchelder (nedbat)
Assigned to: Nobody/Anonymous (nobody)
>Summary: ImportError needs attributes for module and file name

Initial Comment:
Exceptions would be more useful if they had some
structured information attached to them.  For example,
an ImportError could have the name of the module that
could not be imported.  This would make it possible to
deal with exceptions in more powerful ways.

For more discussion:
http://www.nedbatchelder.com/blog/200609.html#e20060906T055924


----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2006-09-16 19:52

Message:
Logged In: YES 
user_id=21627

Exceptions do have structured informations, for example

py> try:
...   open("/tmp/xxx")
... except IOError, e:
...   print e.__dict__
...
{'errno': 2, 'args': (2, 'No such file or directory'),
'strerror': 'No such file or directory', 'filename': '/tmp/xxx'}

It's just that ImportError doesn't, so I'm retitling this
request to restrict attention to ImportError.

If you have other proposals for specific information that
should be on specific exceptions, please submit a separate
issue.

Would you like to work on this specific problem? I think
ImportError should get a module attribute (always set), and
a filename attribute (set only if a file was selected, yet
failed to import; otherwise set to None). It probably will
require some refactoring of C code to simplify raising
ImportError in the importing code.

Explicit raises of ImportError should also be considered;
those in the standard library should be fixed to include
atleast the module; raising ImportError without giving a
module should set the module to None.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1559549&group_id=5470


More information about the Python-bugs-list mailing list