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 eric.snow
Recipients Arfrever, asvetlov, barry, brett.cannon, chris.jerdonek, cvrebert, eric.snow, ezio.melotti, pitrou, serhiy.storchaka
Date 2013-02-20.00:25:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1361319908.42.0.758692422717.issue15767@psf.upfronthosting.co.za>
In-reply-to
Content
The common case for catching ImportError is exactly what ModuleNotFoundError represents.  If people are already going to change their code to handle just this special case, I'd think having the subclass would be the better route.  I find it simpler (both to update existing code and to read:

    try:
        from _thread import _local as local
    except ModuleNotFoundError:
        from _threading_local import local

vs.

    try:
        from _thread import _local as local
    except ImportError as e:
        if e.not_found:
            from _threading_local import local
        else:
            raise

And for the broader case:

    try:
        import breakfast
    except ModuleNotFoundError:
        class breakfast:
            spam = 0
            eggs = 1
            ham = 2
    except ImportError as e:
        log_some_message("uh oh: {}".format(e))
        raise

vs.

    try:
        import breakfast
    except ImportError as e:
        if e.not_found:
            class breakfast:
                spam = 0
                eggs = 1
                ham = 2
        else:
            log_some_message("uh oh: {}".format(e))
            raise
History
Date User Action Args
2013-02-20 00:25:08eric.snowsetrecipients: + eric.snow, barry, brett.cannon, pitrou, ezio.melotti, Arfrever, cvrebert, asvetlov, chris.jerdonek, serhiy.storchaka
2013-02-20 00:25:08eric.snowsetmessageid: <1361319908.42.0.758692422717.issue15767@psf.upfronthosting.co.za>
2013-02-20 00:25:08eric.snowlinkissue15767 messages
2013-02-20 00:25:08eric.snowcreate