[Python-Dev] _not_found attribute on ImportError
brett at python.org
Mon Feb 11 15:44:47 CET 2013
On Mon, Feb 11, 2013 at 9:23 AM, Barry Warsaw <barry at python.org> wrote:
> On Feb 11, 2013, at 09:23 PM, Nick Coghlan wrote:
> >On Mon, Feb 11, 2013 at 8:58 PM, Chris Withers <chris at simplistix.co.uk>
> >> Have any other exceptions grown new attributes in Python 3?
> >Off the top of my head, ImportError grew "name" and "path" attributes
> >in 3.3, everything grew __cause__, __context__ and __traceback__
> >attributes in 3.0 and the __suppress_context__ attribute in 3.3.
> >PEP 3151 may have moved a few attributes around in 3.3 as well.
> >If there are any others, you'll need to trawl the What's New documents
> >looking for them.
> Those public attributes should be documented.
> _not_found should not be since
> it's an implementation detail.
Yep, hence the leading underscore.
> Also, Brett has left little TODO easter eggs
> in the code which clearly indicate changes he plans for 3.4, although I
> know where the plans for ModuleNotFound are documented.
Basically it's a matter of choosing ModuleNotFound vs. ModuleNotFoundError
and then writing the code.
> In the meantime, I just ran a test against trunk, with the following change
> and nothing broke afaict.
> diff -r a79650aacb43 Lib/importlib/_bootstrap.py
> --- a/Lib/importlib/_bootstrap.py Mon Feb 11 13:33:00 2013 +0000
> +++ b/Lib/importlib/_bootstrap.py Mon Feb 11 09:16:51 2013 -0500
> @@ -1640,6 +1640,7 @@
> # TODO(brett): In Python 3.4, have import raise
> # ModuleNotFound and catch that.
> if getattr(exc, '_not_found', False):
> + del exc._not_found
> if exc.name == from_name:
> I won't commit this, but it really needs another hasattr() check to be
> completely valid.
> Python-Dev mailing list
> Python-Dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev