This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: imp.find_module() should not find unimportable modules
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, brett.cannon, ezio.melotti, ncoghlan
Priority: normal Keywords:

Created on 2011-09-25 19:03 by Arfrever, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg144527 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-09-25 19:03
imp.find_module() can find files, which cannot be imported. I suggest that imp.find_module() raise an exception in such cases.

$ cd /tmp
$ touch .something.py
$ python3.3
Python 3.3.0a0 (default:5e456e1a9e8c+, Sep 25 2011, 18:57:23) 
[GCC 4.5.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import .something
  File "<stdin>", line 1
    import .something
           ^
SyntaxError: invalid syntax
>>> module = __import__(".something")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Empty module name
>>> import imp
>>> file, pathname, description = imp.find_module(".something")
>>> file, pathname, description
(<_io.TextIOWrapper name=4 mode='U' encoding='utf-8'>, '.something.py', ('.py', 'U', 1))
msg144528 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-09-25 19:35
I'm not sure they should be disallowed.  We have ways to set variables and attributes with "invalid" names (like '.something') too.  OTOH __import__ fails to import the .something due to the special meaning of the dot, but it imports things like foo-bar.py just fine.
Also I'm assuming that with "unimportable" you just mean "with a name that is not a valid identifier" and not other modules that can't be imported for other reasons.
msg144529 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-09-25 20:03
I mean files, which cannot be imported even by __import__().
I know that __import__() can import foo-bar.py.
msg144546 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2011-09-26 18:06
I'm w/ Ezio on this; imp.find_module() handling modules whose names can't be used by __import__() is fine.
History
Date User Action Args
2022-04-11 14:57:21adminsetgithub: 57255
2011-09-26 18:06:22brett.cannonsetstatus: open -> closed
resolution: not a bug
messages: + msg144546
2011-09-25 20:03:05Arfreversetmessages: + msg144529
2011-09-25 19:35:24ezio.melottisetnosy: + ezio.melotti, brett.cannon, ncoghlan
type: behavior
messages: + msg144528
2011-09-25 19:03:50Arfrevercreate