Skip to content

Commit e329e15

Browse files
committed
Merge pull request #77 from equalsraf/tb-decode-hook-enc
Python3 fixes: functools.partial and encoding
2 parents fd7157a + 234597d commit e329e15

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

neovim/plugin/decorators.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Decorators used by python host plugin system."""
2+
23
import inspect
4+
import logging
35

6+
from ..compat import IS_PYTHON3
47

5-
import logging
68
logger = logging.getLogger(__name__)
79
debug, info, warn = (logger.debug, logger.info, logger.warn,)
810
__all__ = ('plugin', 'rpc_export', 'command', 'autocmd', 'function',
@@ -20,8 +22,11 @@ def plugin(cls):
2022
# decorated functions have a bound Nvim instance as first argument.
2123
# For methods in a plugin-decorated class this is not required, because
2224
# the class initializer will already receive the nvim object.
23-
for _, fn in inspect.getmembers(cls, inspect.ismethod):
24-
if hasattr(fn, '_nvim_bind'):
25+
predicate = lambda fn: hasattr(fn, '_nvim_bind')
26+
for _, fn in inspect.getmembers(cls, predicate):
27+
if IS_PYTHON3:
28+
fn._nvim_bind = False
29+
else:
2530
fn.im_func._nvim_bind = False
2631
return cls
2732

neovim/plugin/host.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def __init__(self, nvim):
3737
'shutdown': self.shutdown
3838
}
3939
self._nvim_encoding = nvim.options['encoding']
40+
if IS_PYTHON3 and isinstance(self._nvim_encoding, bytes):
41+
self._nvim_encoding = self._nvim_encoding.decode('ascii')
4042

4143
def start(self, plugins):
4244
"""Start listening for msgpack-rpc requests and notifications."""
@@ -51,6 +53,8 @@ def shutdown(self):
5153

5254
def _on_request(self, name, args):
5355
"""Handle a msgpack-rpc request."""
56+
if IS_PYTHON3 and isinstance(name, bytes):
57+
name = name.decode(self._nvim_encoding)
5458
handler = self._request_handlers.get(name, None)
5559
if not handler:
5660
msg = 'no request handler registered for "%s"' % name
@@ -64,6 +68,8 @@ def _on_request(self, name, args):
6468

6569
def _on_notification(self, name, args):
6670
"""Handle a msgpack-rpc notification."""
71+
if IS_PYTHON3 and isinstance(name, bytes):
72+
name = name.decode(self._nvim_encoding)
6773
handler = self._notification_handlers.get(name, None)
6874
if not handler:
6975
warn('no notification handler registered for "%s"', name)

0 commit comments

Comments
 (0)