[Python-Dev] unexpected import behaviour (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Sat Jul 31 03:06:42 CEST 2010


On Sat, Jul 31, 2010 at 4:46 AM, Daniel Waterworth <da.waterworth at gmail.com> wrote:

Having thought it through thoroughly, my preference is for a warning.

That's actually harder than it sounds.

Inserting "main" into sys.modules under its normal name as well as "main" is actually pretty easy (for both direct execution and -m). Making it generate a warning when accessing main under its normal name is trickier (akin to the various "lazy module loading" hacks that are available in assorted packages on pypi).

Extending this to work for arbitrary objects is very hard to do efficiently (you'd almost certainly need an additional index from file values to sys.modules keys that would complain whenever the list of associated key entries for a given file value contained more than 1 entry). That's a lot of infrastructure just to try and detect a fairly rare kind of bug.

Cheers, Nick.

-- Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-Dev mailing list