[Python-ideas] proposal: "python -m foo" should bind sys.modules['foo']

Cameron Simpson cs at zip.com.au
Wed Aug 5 11:01:54 CEST 2015


On 05Aug2015 02:14, Eric Snow <ericsnowcurrently at gmail.com> wrote:
>On Aug 4, 2015 11:46 PM, "Cameron Simpson" <cs at zip.com.au> wrote:
>>
>> On 04Aug2015 23:01, Eric Snow <ericsnowcurrently at gmail.com> wrote:
>>> Be sure to read through PEP 495.
>
>Sorry, I meant 395.

Ah, ok, many thanks. I've now read this, particularly this section:

  http://legacy.python.org/dev/peps/pep-0395/#fixing-pickling-without-breaking-introspection

I see that Guido has lent Nick the time machine, as that section outlines a 
scheme almost word for word what I propose. Though not quite.

I see that this was withdrawn, and I after reading the whole PEP and the 
withdrawal statement at the top I think there are two probalems with the PEP.  
One is that, as stated, several of these issues have since been addressed 
elsewhere (though not my issue). The other is that it tried to address a whole 
host of issues which are related more by sharing the import system than 
necessarily being closely related of themselves, though clearly there are 
several scenarios that need considering to ensure that one fix doesn't make 
other things worse.

I still wish to put forth my proposal on its own, probably PEPed, for the 
following reasons:

(a) at present the multiple import via __main__/"python -m" is still not fixed

(b) that the fix here:

  http://legacy.python.org/dev/peps/pep-0395/#fixing-dual-imports-of-the-main-module

seems more oriented around keeping sys.path sane than directly avoiding a dual 
import

(c) my suggestion both reuses __qualname__ proposal almost as PEP495 suggested

(d) can't break anything because modules do not presently have a __qualname__

(e) would automatically remove a very surprising edge case that is very easy to 
trip over i.e. by doing nothing very weird, just plain old imports.

Therefore I'd still like commentry on my quite limited and small proposal, with 
an eye to PEPing it and actually getting it approved.

Cheers,
Cameron Simpson <cs at zip.com.au>

Yesterday, I was running a CNC plasma cutter that's controlled by Windows XP.
This is a machine that moves around a plasma torch that cuts thick steel
plate.  A "New Java update is available" window popped up while I was
working.  Not good. - John Nagle


More information about the Python-ideas mailing list