On Tue, Nov 29, 2016 at 9:19 AM, Nathaniel Smith <n...@pobox.com> wrote: > This also suggests that the overall error-handling flow for 'import > foo' should look like: > > 1) run foo.missing.py > 2) if it raises an exception: propagate that > 3) otherwise, if sys.modules["foo"] is missing: raise some variety of > ImportError. > 4) otherwise, use sys.modules["foo"] as the object that should be > bound to 'foo' in the original invoker's namespace
+1, because this also provides a coherent way to reword the try/except import idiom: # Current idiom # somefile.py try: import foo except ImportError: import subst_foo as foo # New idiom: # foo.missing.py import subst_foo as foo import sys; sys.modules["foo"] = foo #somefile.py import foo ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/