[New-bugs-announce] [issue35375] name shadowing while a module tries to import another
Sriram Krishna
report at bugs.python.org
Sun Dec 2 05:11:52 EST 2018
New submission from Sriram Krishna <ksri91 at gmail.com>:
Suppose I have a file profile.py in the same directory as the file I am running (say test.py)
Let the contents of the files be:
profile.py:
raise Exception
test.py:
import cProfile
now if I run test.py
$ python test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
import cProfile
File "/usr/lib/python3.7/cProfile.py", line 10, in <module>
import profile as _pyprofile
File "/home/username/profile.py", line 1, in <module>
raise Exception
Exception
The file profile.py in '/usr/lib/python3.7' should have been loaded. This would also happen if test.py imported a module or package which imported cProfile.
The only possible way of avoiding this problem completely is by ensuring that the name of any the python files don't match a builtin python file or the name of any installed package.
A python user can't be expected to know the name of every possible file in the Python standard library. Maybe the current working directory should be removed from sys.path when importing from within another module not in the same directory.
----------
components: Interpreter Core
messages: 330874
nosy: ksriram
priority: normal
severity: normal
status: open
title: name shadowing while a module tries to import another
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35375>
_______________________________________
More information about the New-bugs-announce
mailing list