Skip to content

Commit 3efa487

Browse files
authored
Revert: fix "imp" module deprecation warnings (#369)
closes #368 There is more involved with migrating to `find_spec()` and Python's new enterprise-quality API. We may not be able to fashion a compat wrapper that mimics the old find_module() API. - `find_spec()` returns `importlib.machinery.ModuleSpec` object, unlike `find_module()` which returns 3 values. - `host.py` sends the result to `imp.load_module()` ... Reverts the following: 8df2861 a29f34e e29e4df
1 parent b748f91 commit 3efa487

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

pynvim/compat.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,18 @@
22

33
import sys
44
import warnings
5-
if sys.version_info >= (3, 7):
6-
import types
7-
import importlib
8-
else:
9-
import imp # Deprecated in Python 3.7+
10-
if sys.version_info >= (3, 4):
11-
from importlib.machinery import PathFinder
12-
original_find_module = PathFinder.find_spec
13-
else:
14-
from imp import find_module as original_find_module
5+
from imp import find_module as original_find_module
156

167

178
IS_PYTHON3 = sys.version_info >= (3, 0)
189

19-
if sys.version_info >= (3, 7):
20-
load_module = importlib.import_module
21-
new_module = types.ModuleType
22-
else:
23-
load_module = imp.load_module
24-
new_module = imp.new_module
2510

2611
if IS_PYTHON3:
2712
def find_module(fullname, path):
28-
"""Compat wrapper for imp.find_module, or find_spec in Python 3.7+.
13+
"""Compatibility wrapper for imp.find_module.
2914
30-
Automatically decodes arguments (must be Unicode in Python3).
15+
Automatically decodes arguments of find_module, in Python3
16+
they must be Unicode
3117
"""
3218
if isinstance(fullname, bytes):
3319
fullname = fullname.decode()

pynvim/plugin/script_host.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""Legacy python/python3-vim emulation."""
2+
import imp
23
import io
34
import logging
45
import os
56
import sys
67

78
from .decorators import plugin, rpc_export
89
from ..api import Nvim, walk
9-
from ..compat import IS_PYTHON3, find_module, load_module, new_module
10+
from ..compat import IS_PYTHON3
1011
from ..msgpack_rpc import ErrorResponse
1112
from ..util import format_exc_skip
1213

@@ -36,7 +37,7 @@ def __init__(self, nvim):
3637
"""Initialize the legacy python-vim environment."""
3738
self.setup(nvim)
3839
# context where all code will run
39-
self.module = new_module('__main__')
40+
self.module = imp.new_module('__main__')
4041
nvim.script_context = self.module
4142
# it seems some plugins assume 'sys' is already imported, so do it now
4243
exec('import sys', self.module.__dict__)
@@ -215,11 +216,11 @@ def _find_module(fullname, oldtail, path):
215216
if idx > 0:
216217
name = oldtail[:idx]
217218
tail = oldtail[idx + 1:]
218-
fmr = find_module(name, path)
219-
module = find_module(fullname[:-len(oldtail)] + name, *fmr)
219+
fmr = imp.find_module(name, path)
220+
module = imp.find_module(fullname[:-len(oldtail)] + name, *fmr)
220221
return _find_module(fullname, tail, module.__path__)
221222
else:
222-
return find_module(fullname, path)
223+
return imp.find_module(fullname, path)
223224

224225
class VimModuleLoader(object):
225226
def __init__(self, module):
@@ -231,7 +232,7 @@ def load_module(self, fullname, path=None):
231232
return sys.modules[fullname]
232233
except KeyError:
233234
pass
234-
return load_module(fullname, *self.module)
235+
return imp.load_module(fullname, *self.module)
235236

236237
class VimPathFinder(object):
237238
@staticmethod

0 commit comments

Comments
 (0)