Skip to content

Commit ceeebf6

Browse files
committed
use importlib.machinery when available
avoids deprecation warning on startup, and allows tests to pass with PYTHONWARNINGS=d closes ipython#4051 candidate for backport to 1.2
1 parent 04ab404 commit ceeebf6

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎IPython/core/completerlib.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@
1717

1818
# Stdlib imports
1919
import glob
20-
import imp
2120
import inspect
2221
import os
2322
import re
2423
import sys
2524

25+
try:
26+
# Python 3
27+
from importlib.machinery import all_suffixes
28+
_suffixes = all_suffixes()
29+
except ImportError:
30+
from imp import get_suffixes
31+
_suffixes = [ s[0] for s in get_suffixes() ]
32+
2633
# Third-party imports
2734
from time import time
2835
from zipimport import zipimporter
@@ -51,7 +58,7 @@
5158
import_re = re.compile(r'(?P<name>[a-zA-Z_][a-zA-Z0-9_]*?)'
5259
r'(?P<package>[/\\]__init__)?'
5360
r'(?P<suffix>%s)$' %
54-
r'|'.join(re.escape(s[0]) for s in imp.get_suffixes()))
61+
r'|'.join(re.escape(s) for s in _suffixes))
5562

5663
# RE for the ipython %run command (python + ipython scripts)
5764
magic_run_re = re.compile(r'.*(\.ipy|\.ipynb|\.py[w]?)$')

0 commit comments

Comments
 (0)