util: Make decode_bytes work correctly with neovim

Neovim with python3 behaves differently than vim with python3 (former
returns str for variable queries, latter bytes).
This commit is contained in:
Tomas Babej 2017-01-07 18:59:14 +01:00
parent c1d1dcd1f1
commit ea6faa923f

View file

@ -14,7 +14,7 @@ from taskwiki import regexp
# Detect if command AnsiEsc is available
ANSI_ESC_AVAILABLE = vim.eval('exists(":AnsiEsc")') == '2'
NEOVIM = (vim.eval('has("nvim")') == "1")
def tw_modstring_to_args(line):
output = []
@ -387,9 +387,13 @@ def enforce_dependencies(cache):
def decode_bytes(var):
"""
Data structures obtained from vim under python3 will return bytestrings.
Neovim under python3 will return str.
Make sure we can handle that.
"""
if NEOVIM:
return var
if isinstance(var, bytes):
return var.decode()