Skip to content

Commit 8ddbdce

Browse files
Alternate code path for deprectated imp functions in Python 3.3
fixes #296
1 parent f835cfa commit 8ddbdce

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

bpython/importcompletion.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
import os
2828
import sys
2929
import warnings
30+
31+
if sys.version_info[0] == 3 and sys.version_info[1] >= 3:
32+
import importlib.machinery
33+
SUFFIXES = importlib.machinery.all_suffixes()
34+
else:
35+
SUFFIXES = [suffix for suffix, mode, type in imp.get_suffixes()]
36+
3037
try:
3138
from warnings import catch_warnings
3239
except ImportError:
@@ -124,17 +131,17 @@ def find_modules(path):
124131
except EnvironmentError:
125132
filenames = []
126133
for name in filenames:
127-
if not any(name.endswith(suffix[0]) for suffix in imp.get_suffixes()):
134+
if not any(name.endswith(suffix) for suffix in SUFFIXES):
128135
# Possibly a package
129136
if '.' in name:
130137
continue
131138
elif os.path.isdir(os.path.join(path, name)):
132139
# Unfortunately, CPython just crashes if there is a directory
133140
# which ends with a python extension, so work around.
134141
continue
135-
for suffix in imp.get_suffixes():
136-
if name.endswith(suffix[0]):
137-
name = name[:-len(suffix[0])]
142+
for suffix in SUFFIXES:
143+
if name.endswith(suffix):
144+
name = name[:-len(suffix)]
138145
break
139146
if py3 and name == "badsyntax_pep3120":
140147
# Workaround for issue #166

0 commit comments

Comments
 (0)