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 ncoghlan
Recipients Arfrever, christian.heimes, georg.brandl, loewis, mark.dickinson, meador.inge, ncoghlan, pitrou, python-dev, skrah, vstinner
Date 2012-08-12.10:43:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1344768240.12.0.618879773058.issue15573@psf.upfronthosting.co.za>
In-reply-to
Content
We do import modules in the Object/* code if we really need to (Grep for "PyImport_Import" in the Objects dir)

It seems to me like this case is rapidly reaching (or has even gone well past) the point where that's the sensible thing to do.

A couple of key issues of concern are:
- the number of modules implicitly imported at startup
- the risk of attempting to import a module before the import system (and the interpreter in general) is fully initialised

A simple trick for alleviating both concerns is to call PyImport_Import directly in the code path that needs it. It will be pretty quick if it gets a hit in the sys.modules cache, and most of the builtin objects aren't *used* until well after the interpreter is fully initialised (and, in the case of memoryview equality comparisons, often won't be used at all).

The main alternative is to invert the dependency: move the desired functionality into a private API function and have the standard library extension module access it that way. This can end up being harder to maintain, though, and certainly isn't appropriate in this case (since "_struct.unpack_from" needs the full struct machinery to do the job).
History
Date User Action Args
2012-08-12 10:44:00ncoghlansetrecipients: + ncoghlan, loewis, georg.brandl, mark.dickinson, pitrou, vstinner, christian.heimes, Arfrever, skrah, meador.inge, python-dev
2012-08-12 10:44:00ncoghlansetmessageid: <1344768240.12.0.618879773058.issue15573@psf.upfronthosting.co.za>
2012-08-12 10:43:59ncoghlanlinkissue15573 messages
2012-08-12 10:43:59ncoghlancreate