On 11 Aug 2013 21:37, "PJ Eby" <pje@telecommunity.com> wrote:
>
> On Sun, Aug 11, 2013 at 7:31 PM, Jason R. Coombs <jaraco@jaraco.com> wrote:
> >> -----Original Message-----
> >> From: Nick Coghlan [mailto:ncoghlan@gmail.com]
> >> Sent: Sunday, 11 August, 2013 17:14
> >>
> >> We actually have a proposal on import-sig to allow module specific import
> >> path manipulation (including the ability to say "don't import this module
> >> from this directory, even though it looks like it is here"). I'd favour that
> >> mechanism over a new "not importable" file extension.
> >
> > I don't believe this mechanism would suffice. My previous example was
> > over-simplified to the general problem, which is that any script could
> > potentially be imported as a module of the same name. So if I were to launch
> > easy_install.py, it would set sys.path[0] to Scripts\ and if it were then to
> > import cython (which it does), it would import Scripts/cython.py as cython,
> > unless there were some way to globally declare all installed scripts somewhere
> > so they're excluded from import.
>
> Indeed. It really *does* need to be a "don't import this" extension,
> though it doesn't much matter what that extension is. Except on
> Windows, of course, where it has to be something associated with
> Python that also still works as a console app and is listed in
> PATHEXT.
>
> (As you surmised earlier, my choice of '-script.py' was indeed chosen
> to prevent accidental importing, as the '-' ensures it's not a valid
> module name.)
Having an empty "cython.ref" file (extension TBC) would tell Python to skip that directory for "import cython" regardless of the presence of something that otherwise would be considered. The actual downside is that won't land until 3.4 at the earliest, while PyLauncher can associate additional extensions with itself (and modify PATHEXT) earlier than that.
Having pys and pyz for "executable, but not importable" (source and zip archive forms) could be quite clean. In effect, the pys extension would bring windows to parity with *nix, where "no extension at all" has traditionally served the purpose of making it impossible to import a script.
Cheers,
Nick.