[issue13047] imp.find_module("") and imp.find_module(".")
New submission from Arfrever Frehtes Taifersar Arahesis <Arfrever.FTA@GMail.Com>: It's undocumented that imp.find_module("") and imp.find_module(".") try to find __init__.py. There is also a small difference in behavior between them. sys.path by default contains "" as the first element, which is sufficient for imp.find_module("."), but not for imp.find_module(""): $ mkdir /tmp/imp_tests $ cd /tmp/imp_tests $ touch __init__.py $ python3.3 -c 'import imp, sys; print(repr(sys.path[0])); print(imp.find_module("."))' '' (None, '.', ('', '', 5)) $ python3.3 -c 'import imp, sys; print(repr(sys.path[0])); print(imp.find_module(""))' '' Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named '' If sys.path contains path (e.g. "." or absolute path) to directory with __init__.py file, then imp.find_module("") will succeed: $ PYTHONPATH="." python3.3 -c 'import imp, sys; print(repr(sys.path[0:2])); print(imp.find_module("."))' ['', '/tmp/imp_tests'] (None, '.', ('', '', 5)) $ PYTHONPATH="." python3.3 -c 'import imp, sys; print(repr(sys.path[0:2])); print(imp.find_module(""))' ['', '/tmp/imp_tests'] (None, '/tmp/imp_tests/', ('', '', 5)) $ python3.3 -c 'import imp, sys; sys.path.insert(1, "."); print(repr(sys.path[0:2])); print(imp.find_module("."))' ['', '.'] (None, '.', ('', '', 5)) $ python3.3 -c 'import imp, sys; sys.path.insert(1, "."); print(repr(sys.path[0:2])); print(imp.find_module(""))' ['', '.'] (None, './', ('', '', 5)) I think that imp.find_module(".") and imp.find_module("") should have the same behavior, and this behavior should be documented. ---------- assignee: docs@python components: Documentation, Interpreter Core messages: 144531 nosy: Arfrever, docs@python priority: normal severity: normal status: open title: imp.find_module("") and imp.find_module(".") versions: Python 2.7, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13047> _______________________________________
Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- nosy: +brett.cannon, ezio.melotti, ncoghlan _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13047> _______________________________________
Brett Cannon <brett@python.org> added the comment: I don't think this is undocumented as much as it's unexpected behavior. I really doubt this functionality was on purpose. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13047> _______________________________________
Changes by Brett Cannon <brett@python.org>: ---------- nosy: -brett.cannon _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13047> _______________________________________
Batuhan <batuhanosmantaskaya@gmail.com> added the comment: `imp` is now deprecated and IMHO no reason to make this change after this deprecation. ---------- nosy: +BTaskaya _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue13047> _______________________________________
Change by Irit Katriel <iritkatriel@yahoo.com>: ---------- resolution: -> out of date stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue13047> _______________________________________
participants (5)
-
Arfrever Frehtes Taifersar Arahesis
-
Batuhan
-
Brett Cannon
-
Ezio Melotti
-
Irit Katriel