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 dw
Recipients dw
Date 2018-12-14.01:10:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1544749825.35.0.788709270274.issue35486@psf.upfronthosting.co.za>
In-reply-to
Content
Having considered this for a few hours, it seems the following is clear:

- 3.6 introduces ModuleImportError
- 3.7 begins using it within importlib
- 3.8 first instance of stdlib code catching it

- PEP-302 and PEP-451 are the definitive specifications for how sys.meta_path is supposed to work, and neither makes mention of ModuleNotFoundError. It seems at least this should have been flagged during review of the original change, but apparently the name of the exception was more important.

- The recent work done to move most of the import machinery on to sys.meta_path has exposed a set of import hooks that don't quite comply to the documented import hook interface

- The newly advertised ModuleNotFoundError appearing in stack traces for everyone means that more people will continue to write new cases of "except ModuleNotFoundError:", which while following best practice (catch most specific relevant exception), at present it amounts to relying on an implementation detail of the default importer. GitHub search reveals this to be an accurate reading: https://github.com/search?q=%22except+ModuleNotFoundError%22&type=Code

Therefore we are in a position where:

- Natural developer habit will cause much more protocol-violating code to exist over time, there is no option to stop this process
- New import hooks written against the existing documentation will break in the face of developer habit
- Existing import hooks were broken in Python 3.6 and this is not documented anywhere
- Python's own import machinery contravenes its specification

Options:

- Updating PEP-302 to mention introduction of the new exception type
- Updating ModuleNotFoundError/ImportError documentation to somehow capture the compatibility issue
History
Date User Action Args
2018-12-14 01:10:25dwsetrecipients: + dw
2018-12-14 01:10:25dwsetmessageid: <1544749825.35.0.788709270274.issue35486@psf.upfronthosting.co.za>
2018-12-14 01:10:25dwlinkissue35486 messages
2018-12-14 01:10:22dwcreate