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.

Author chris.jerdonek
Recipients Arfrever, Guido.van.Rossum, asvetlov, barry, brett.cannon, chris.jerdonek, cvrebert, cwg, eric.snow, ezio.melotti, gvanrossum, jcea, pitrou, python-dev, serhiy.storchaka, theller
Date 2018-02-27.11:27:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519730847.09.0.467229070634.issue15767@psf.upfronthosting.co.za>
In-reply-to
Content
Eric touched on the use when he said the following above:

> It's nice to be able to distinguish between the failure to *find* the module during import from other uses of ImportError.

To make up one example, you might want to use a fallback module if a package isn't installed:

    try:
        from fancy_parser import NewParser as HTMLParser
    except ModuleNotFoundError:
        from html.parser import HTMLParser

But you might still want an error if the package is installed, though incorrectly (e.g. fancy_parser is installed, but an old version that doesn't have NewParser). Catching ImportError would swallow this error, whereas ModuleNotFoundError would let it bubble up.
History
Date User Action Args
2018-02-27 11:27:27chris.jerdoneksetrecipients: + chris.jerdonek, gvanrossum, barry, brett.cannon, theller, jcea, pitrou, ezio.melotti, Arfrever, cvrebert, asvetlov, python-dev, eric.snow, serhiy.storchaka, Guido.van.Rossum, cwg
2018-02-27 11:27:27chris.jerdoneksetmessageid: <1519730847.09.0.467229070634.issue15767@psf.upfronthosting.co.za>
2018-02-27 11:27:27chris.jerdoneklinkissue15767 messages
2018-02-27 11:27:27chris.jerdonekcreate