Skip to content

Commit d53415d

Browse files
authored
Merge pull request #274 from lambdalisue/master
Fix 'SyntaxError: invalid syntax' on Python 3.7 alpha pre-release
2 parents 1ab98e8 + a9a3a70 commit d53415d

File tree

10 files changed

+49
-26
lines changed

10 files changed

+49
-26
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ below.
7676
computations. Intensive computations should be done in a separate thread (or
7777
process), and `vim.async_call` can be used to send results back to nvim.
7878

79-
* Some methods accept an `async` keyword argument: `vim.eval`, `vim.command`,
79+
* Some methods accept an `async_` keyword argument: `vim.eval`, `vim.command`,
8080
`vim.request` as well as the `vim.funcs` and `vim.api` wrappers. When
81-
`async=True` is passed the client will not wait for nvim to complete the
81+
`async_=True` is passed the client will not wait for nvim to complete the
8282
request (which also means that the return value is unavailable).
8383

8484
#### Remote (new-style) plugins
@@ -122,7 +122,7 @@ requests without nvim confusing these requests with requests from a synchronous
122122
handler. To execute an asynchronous handler even when other handlers are
123123
running, add `allow_nested=True` to the decorator. The handler must then not
124124
make synchronous nvim requests, but it can make asynchronous requests, i e
125-
passing `async=True`.
125+
passing `async_=True`.
126126

127127
You need to run `:UpdateRemotePlugins` in nvim for changes in the specifications
128128
to have effect. For details see `:help remote-plugin` in nvim.

docs/usage/python-plugin-api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Note that this code will still block the plugin host if it does long-running com
5858
Intensive computations should be done in a separate thread (or process),
5959
and ``vim.async_call`` can be used to send results back to Neovim.
6060

61-
Some methods accept an ``async`` keyword argument:
61+
Some methods accept an ``async_`` keyword argument:
6262
``vim.eval``, ``vim.command``, ``vim.request`` as well as the ``vim.funcs`` and ``vim.api`` wrappers.
63-
When ``async=True`` is passed the client will not wait for Neovim to complete the request
63+
When ``async_=True`` is passed the client will not wait for Neovim to complete the request
6464
(which also means that the return value is unavailable).

docs/usage/remote-plugins.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ This ensures that async handlers can call requests without Neovim confusing thes
4242
To execute an asynchronous handler even when other handlers are running,
4343
add ``allow_nested=True`` to the decorator.
4444
The handler must then not make synchronous Neovim requests,
45-
but it can make asynchronous requests, i.e. passing ``async=True``.
45+
but it can make asynchronous requests, i.e. passing ``async_=True``.
4646

4747
You need to run ``:UpdateRemotePlugins`` in Neovim for changes in the specifications to have effect.
4848
For details see ``:help remote-plugin`` in Neovim.

neovim/api/buffer.py

Lines changed: 9 additions & 7 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,17 +98,19 @@ 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,
106-
line, col_start, col_end, async=async)
106+
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,
111-
line_start, line_end, async=async)
113+
line_start, line_end, async_=async_)
112114

113115
@property
114116
def name(self):

neovim/api/nvim.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,16 @@ def request(self, name, *args, **kwargs):
122122
functions have python wrapper functions. The `api` object can
123123
be also be used to call API functions as methods:
124124
125-
vim.api.err_write('ERROR\n', async=True)
125+
vim.api.err_write('ERROR\n', async_=True)
126126
vim.current.buffer.api.get_mark('.')
127127
128128
is equivalent to
129129
130-
vim.request('nvim_err_write', 'ERROR\n', async=True)
130+
vim.request('nvim_err_write', 'ERROR\n', async_=True)
131131
vim.request('nvim_buf_get_mark', vim.current.buffer, '.')
132132
133133
134-
Normally a blocking request will be sent. If the `async` flag is
134+
Normally a blocking request will be sent. If the `async_` flag is
135135
present and True, a asynchronous notification is sent instead. This
136136
will never block, and the return value or error is ignored.
137137
"""

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: 7 additions & 5 deletions
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,)
@@ -72,12 +74,12 @@ def request(self, method, *args, **kwargs):
7274
- Run the loop until the response is available
7375
- Put requests/notifications received while waiting into a queue
7476
75-
If the `async` flag is present and True, a asynchronous notification is
76-
sent instead. This will never block, and the return value or error is
77-
ignored.
77+
If the `async_` flag is present and True, a asynchronous notification
78+
is sent instead. This will never block, and the return value or error
79+
is ignored.
7880
"""
79-
async = kwargs.pop('async', False)
80-
if async:
81+
async_ = check_async(kwargs.pop('async_', None), kwargs, False)
82+
if async_:
8183
self._async_session.notify(method, args)
8284
return
8385

neovim/plugin/host.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, nvim):
4646
self._decode_default = IS_PYTHON3
4747

4848
def _on_async_err(self, msg):
49-
self.nvim.err_write(msg, async=True)
49+
self.nvim.err_write(msg, async_=True)
5050

5151
def start(self, plugins):
5252
"""Start listening for msgpack-rpc requests and notifications."""

test/test_client_rpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def request_cb(name, args):
4444
vim.stop_loop()
4545

4646
# this would have dead-locked if not async
47-
vim.funcs.rpcrequest(vim.channel_id, "test-event", async=True)
47+
vim.funcs.rpcrequest(vim.channel_id, "test-event", async_=True)
4848
vim.run_loop(request_cb, None, None)
4949
eq(vim.vars['result'], 17)
5050

test/test_events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ def test_receiving_events():
1919
@with_setup(setup=cleanup)
2020
def test_sending_notify():
2121
# notify after notify
22-
vim.command("let g:test = 3", async=True)
22+
vim.command("let g:test = 3", async_=True)
2323
cmd = 'call rpcnotify(%d, "test-event", g:test)' % vim.channel_id
24-
vim.command(cmd, async=True)
24+
vim.command(cmd, async_=True)
2525
event = vim.next_message()
2626
eq(event[1], 'test-event')
2727
eq(event[2], [3])
2828

2929
# request after notify
30-
vim.command("let g:data = 'xyz'", async=True)
30+
vim.command("let g:data = 'xyz'", async_=True)
3131
eq(vim.eval('g:data'), 'xyz')
3232

3333

0 commit comments

Comments
 (0)