Skip to content

Commit 5a5dfee

Browse files
committed
Treat an empty path like the CWD and work around a bug in Python's imp module.
Unfortunately, "imp.find_module()" crashes when there is a directory which ends with a Python extension. See http://bugs.python.org/issue7732
1 parent c6ce270 commit 5a5dfee

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

bpython/importcompletion.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def find_modules(path):
7575
# Possibly a package
7676
if '.' in name:
7777
continue
78+
elif os.path.isdir(os.path.join(path, name)):
79+
# Unfortunately, CPython just crashes if there is a directory
80+
# which ends with a python extension, so work around.
81+
continue
7882
name = os.path.splitext(name)[0]
7983
try:
8084
fo, pathname, _ = imp.find_module(name, [path])
@@ -99,6 +103,8 @@ def find_all_modules(path=None):
99103
path = sys.path
100104

101105
for p in path:
106+
if not path:
107+
path = os.curdir
102108
for module in find_modules(p):
103109
modules.add(module)
104110
yield

0 commit comments

Comments
 (0)