[Python-ideas] Disallow importing the same module under multiple names

Nick Coghlan ncoghlan at gmail.com
Wed Mar 21 07:36:39 EDT 2018


On 21 March 2018 at 10:01, Chris Billington <chrisjbillington at gmail.com>
wrote:

>
>
> On Wed, Mar 21, 2018 at 10:58 AM, Chris Billington <
> chrisjbillington at gmail.com> wrote:
>
>> I don't think that's true:
>>
>>
>>
>> On Wed, Mar 21, 2018 at 10:51 AM, Greg Ewing <greg.ewing at canterbury.ac.nz
>> > wrote:
>>
>>> Chris Billington wrote:
>>>
>>>> I wonder how mercurial gets around the fact that its own imports might
>>>> be shadowed by whatever's in the current working directory.
>>>>
>>>
>>> The cwd is only added to sys.path in the interactive interpreter,
>>> not when you run "python something.py". So it's not usually a
>>> problem for applications implemented in Python.
>>>
>>>
>> I don't think that's true:
>>
>> $ cd /tmp
>> $ echo 'import bar' > foo.py
>> $ echo 'print("this is bar")' > bar.py
>> $ python foo.py
>> this is bar
>>
>> (/tmp is not in the python path)
>>
>>
> Actually I'm mistaken. That's the directory of the script being added to
> the path, not the current working directory.
>

Scripts add the directory of the script, but the "-m" switch adds the
current directory in order to locate modules and packages it can find there
(although it's possible we'll attempt to figure out a way to change that in
the future and require folks to explicitly opt-in to cwd relative main
module imports: https://bugs.python.org/issue33053).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180321/4981e8d0/attachment.html>


More information about the Python-ideas mailing list