forked from VimPlug/jedi
Get rid of the imp library import in Python3 to avoid warnings, fixes #1001
This commit is contained in:
@@ -3,7 +3,6 @@ To ensure compatibility from Python ``2.7`` - ``3.x``, a module has been
|
|||||||
created. Clearly there is huge need to use conforming syntax.
|
created. Clearly there is huge need to use conforming syntax.
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
import imp
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import pkgutil
|
import pkgutil
|
||||||
@@ -108,6 +107,9 @@ def find_module_py33(string, path=None, loader=None, full_name=None):
|
|||||||
|
|
||||||
|
|
||||||
def find_module_pre_py33(string, path=None, full_name=None):
|
def find_module_pre_py33(string, path=None, full_name=None):
|
||||||
|
# This import is here, because in other places it will raise a
|
||||||
|
# DeprecationWarning.
|
||||||
|
import imp
|
||||||
try:
|
try:
|
||||||
module_file, module_path, description = imp.find_module(string, path)
|
module_file, module_path, description = imp.find_module(string, path)
|
||||||
module_type = description[2]
|
module_type = description[2]
|
||||||
@@ -217,6 +219,16 @@ class ImplicitNSInfo(object):
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.paths = paths
|
self.paths = paths
|
||||||
|
|
||||||
|
|
||||||
|
if is_py3:
|
||||||
|
all_suffixes = importlib.machinery.all_suffixes
|
||||||
|
else:
|
||||||
|
def all_suffixes():
|
||||||
|
# Is deprecated and raises a warning in Python 3.6.
|
||||||
|
import imp
|
||||||
|
return [suffix for suffix, _, _ in imp.get_suffixes()]
|
||||||
|
|
||||||
|
|
||||||
# unicode function
|
# unicode function
|
||||||
try:
|
try:
|
||||||
unicode = unicode
|
unicode = unicode
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import imp
|
|
||||||
|
|
||||||
from jedi._compatibility import find_module, cast_path, force_unicode, iter_modules
|
from jedi._compatibility import find_module, cast_path, force_unicode, \
|
||||||
|
iter_modules, all_suffixes
|
||||||
from jedi.evaluate.compiled import access
|
from jedi.evaluate.compiled import access
|
||||||
from jedi import parser_utils
|
from jedi import parser_utils
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ def _get_init_path(directory_path):
|
|||||||
The __init__ file can be searched in a directory. If found return it, else
|
The __init__ file can be searched in a directory. If found return it, else
|
||||||
None.
|
None.
|
||||||
"""
|
"""
|
||||||
for suffix, _, _ in imp.get_suffixes():
|
for suffix in all_suffixes():
|
||||||
path = os.path.join(directory_path, '__init__' + suffix)
|
path = os.path.join(directory_path, '__init__' + suffix)
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
return path
|
return path
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import imp
|
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from parso import python_bytes_to_unicode
|
from parso import python_bytes_to_unicode
|
||||||
|
|
||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi._compatibility import iter_modules
|
from jedi._compatibility import iter_modules, all_suffixes
|
||||||
from jedi.evaluate.filters import GlobalNameFilter, ContextNameMixin, \
|
from jedi.evaluate.filters import GlobalNameFilter, ContextNameMixin, \
|
||||||
AbstractNameDefinition, ParserTreeFilter, DictFilter, MergedFilter
|
AbstractNameDefinition, ParserTreeFilter, DictFilter, MergedFilter
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
@@ -107,7 +106,7 @@ class ModuleContext(TreeContext):
|
|||||||
:return: The path to the directory of a package. None in case it's not
|
:return: The path to the directory of a package. None in case it's not
|
||||||
a package.
|
a package.
|
||||||
"""
|
"""
|
||||||
for suffix, _, _ in imp.get_suffixes():
|
for suffix in all_suffixes():
|
||||||
ending = '__init__' + suffix
|
ending = '__init__' + suffix
|
||||||
py__file__ = self.py__file__()
|
py__file__ = self.py__file__()
|
||||||
if py__file__ is not None and py__file__.endswith(ending):
|
if py__file__ is not None and py__file__.endswith(ending):
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import imp
|
|
||||||
|
|
||||||
from jedi._compatibility import unicode, force_unicode
|
from jedi._compatibility import unicode, force_unicode, all_suffixes
|
||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi.evaluate.base_context import ContextualizedNode
|
from jedi.evaluate.base_context import ContextualizedNode
|
||||||
from jedi.evaluate.helpers import is_string
|
from jedi.evaluate.helpers import is_string
|
||||||
@@ -198,7 +197,7 @@ def dotted_path_in_sys_path(sys_path, module_path):
|
|||||||
Returns the dotted path inside a sys.path.
|
Returns the dotted path inside a sys.path.
|
||||||
"""
|
"""
|
||||||
# First remove the suffix.
|
# First remove the suffix.
|
||||||
for suffix, _, _ in imp.get_suffixes():
|
for suffix in all_suffixes():
|
||||||
if module_path.endswith(suffix):
|
if module_path.endswith(suffix):
|
||||||
module_path = module_path[:-len(suffix)]
|
module_path = module_path[:-len(suffix)]
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user