Skip to content

Commit 2bad222

Browse files
committed
Allow 'async' for backward-compatibility
This commit should be reverted sometime in the future.
1 parent 2a0cb3c commit 2bad222

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

neovim/api/buffer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""API for working with a Nvim Buffer."""
22
from .common import Remote
3-
from ..compat import IS_PYTHON3
3+
from ..compat import IS_PYTHON3, check_async
44

55

66
__all__ = ('Buffer')
@@ -98,15 +98,17 @@ def range(self, start, end):
9898
return Range(self, start, end)
9999

100100
def add_highlight(self, hl_group, line, col_start=0,
101-
col_end=-1, src_id=-1, async_=None):
101+
col_end=-1, src_id=-1, async_=None,
102+
**kwargs):
102103
"""Add a highlight to the buffer."""
103-
if async_ is None:
104-
async_ = (src_id != 0)
104+
async_ = check_async(async_, kwargs, src_id != 0)
105105
return self.request('nvim_buf_add_highlight', src_id, hl_group,
106106
line, col_start, col_end, async_=async_)
107107

108-
def clear_highlight(self, src_id, line_start=0, line_end=-1, async_=True):
108+
def clear_highlight(self, src_id, line_start=0, line_end=-1, async_=None,
109+
**kwargs):
109110
"""Clear highlights from the buffer."""
111+
async_ = check_async(async_, kwargs, True)
110112
self.request('nvim_buf_clear_highlight', src_id,
111113
line_start, line_end, async_=async_)
112114

neovim/compat.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Code for supporting compatibility across python versions."""
22

33
import sys
4+
import warnings
45
from imp import find_module as original_find_module
56

67

@@ -36,3 +37,21 @@ def find_module(fullname, path):
3637
unicode_errors_default = 'strict'
3738

3839
NUM_TYPES = (int, long, float)
40+
41+
42+
def check_async(async_, kwargs, default):
43+
"""Return a value of 'async' in kwargs or default when async_ is None
44+
45+
This helper function exists for backward compatibility (See #274).
46+
It shows a warning message when 'async' in kwargs is used to note users.
47+
"""
48+
if async_ is not None:
49+
return async_
50+
elif 'async' in kwargs:
51+
warnings.warn(
52+
'"async" attribute is deprecated. Use "async_" instead.',
53+
DeprecationWarning,
54+
)
55+
return kwargs.pop('async')
56+
else:
57+
return default

neovim/msgpack_rpc/session.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import greenlet
77

8+
from ..compat import check_async
9+
810
logger = logging.getLogger(__name__)
911
error, debug, info, warn = (logger.error, logger.debug, logger.info,
1012
logger.warning,)
@@ -76,7 +78,7 @@ def request(self, method, *args, **kwargs):
7678
is sent instead. This will never block, and the return value or error
7779
is ignored.
7880
"""
79-
async_ = kwargs.pop('async_', False)
81+
async_ = check_async(kwargs.pop('async_', None), kwargs, False)
8082
if async_:
8183
self._async_session.notify(method, args)
8284
return

0 commit comments

Comments
 (0)