Skip to content

Commit

Permalink
Merge pull request #274 from lambdalisue/master
Browse files Browse the repository at this point in the history
Fix 'SyntaxError: invalid syntax' on Python 3.7 alpha pre-release
  • Loading branch information
bfredl committed Apr 22, 2018
2 parents 1ab98e8 + a9a3a70 commit d53415d
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 26 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ below.
computations. Intensive computations should be done in a separate thread (or
process), and `vim.async_call` can be used to send results back to nvim.

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

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

You need to run `:UpdateRemotePlugins` in nvim for changes in the specifications
to have effect. For details see `:help remote-plugin` in nvim.
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/python-plugin-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Note that this code will still block the plugin host if it does long-running com
Intensive computations should be done in a separate thread (or process),
and ``vim.async_call`` can be used to send results back to Neovim.

Some methods accept an ``async`` keyword argument:
Some methods accept an ``async_`` keyword argument:
``vim.eval``, ``vim.command``, ``vim.request`` as well as the ``vim.funcs`` and ``vim.api`` wrappers.
When ``async=True`` is passed the client will not wait for Neovim to complete the request
When ``async_=True`` is passed the client will not wait for Neovim to complete the request
(which also means that the return value is unavailable).
2 changes: 1 addition & 1 deletion docs/usage/remote-plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This ensures that async handlers can call requests without Neovim confusing thes
To execute an asynchronous handler even when other handlers are running,
add ``allow_nested=True`` to the decorator.
The handler must then not make synchronous Neovim requests,
but it can make asynchronous requests, i.e. passing ``async=True``.
but it can make asynchronous requests, i.e. passing ``async_=True``.

You need to run ``:UpdateRemotePlugins`` in Neovim for changes in the specifications to have effect.
For details see ``:help remote-plugin`` in Neovim.
Expand Down
16 changes: 9 additions & 7 deletions neovim/api/buffer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""API for working with a Nvim Buffer."""
from .common import Remote
from ..compat import IS_PYTHON3
from ..compat import IS_PYTHON3, check_async


__all__ = ('Buffer')
Expand Down Expand Up @@ -98,17 +98,19 @@ def range(self, start, end):
return Range(self, start, end)

def add_highlight(self, hl_group, line, col_start=0,
col_end=-1, src_id=-1, async=None):
col_end=-1, src_id=-1, async_=None,
**kwargs):
"""Add a highlight to the buffer."""
if async is None:
async = (src_id != 0)
async_ = check_async(async_, kwargs, src_id != 0)
return self.request('nvim_buf_add_highlight', src_id, hl_group,
line, col_start, col_end, async=async)
line, col_start, col_end, async_=async_)

def clear_highlight(self, src_id, line_start=0, line_end=-1, async=True):
def clear_highlight(self, src_id, line_start=0, line_end=-1, async_=None,
**kwargs):
"""Clear highlights from the buffer."""
async_ = check_async(async_, kwargs, True)
self.request('nvim_buf_clear_highlight', src_id,
line_start, line_end, async=async)
line_start, line_end, async_=async_)

@property
def name(self):
Expand Down
6 changes: 3 additions & 3 deletions neovim/api/nvim.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ def request(self, name, *args, **kwargs):
functions have python wrapper functions. The `api` object can
be also be used to call API functions as methods:
vim.api.err_write('ERROR\n', async=True)
vim.api.err_write('ERROR\n', async_=True)
vim.current.buffer.api.get_mark('.')
is equivalent to
vim.request('nvim_err_write', 'ERROR\n', async=True)
vim.request('nvim_err_write', 'ERROR\n', async_=True)
vim.request('nvim_buf_get_mark', vim.current.buffer, '.')
Normally a blocking request will be sent. If the `async` flag is
Normally a blocking request will be sent. If the `async_` flag is
present and True, a asynchronous notification is sent instead. This
will never block, and the return value or error is ignored.
"""
Expand Down
19 changes: 19 additions & 0 deletions neovim/compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Code for supporting compatibility across python versions."""

import sys
import warnings
from imp import find_module as original_find_module


Expand Down Expand Up @@ -36,3 +37,21 @@ def find_module(fullname, path):
unicode_errors_default = 'strict'

NUM_TYPES = (int, long, float)


def check_async(async_, kwargs, default):
"""Return a value of 'async' in kwargs or default when async_ is None
This helper function exists for backward compatibility (See #274).
It shows a warning message when 'async' in kwargs is used to note users.
"""
if async_ is not None:
return async_
elif 'async' in kwargs:
warnings.warn(
'"async" attribute is deprecated. Use "async_" instead.',
DeprecationWarning,
)
return kwargs.pop('async')
else:
return default
12 changes: 7 additions & 5 deletions neovim/msgpack_rpc/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import greenlet

from ..compat import check_async

logger = logging.getLogger(__name__)
error, debug, info, warn = (logger.error, logger.debug, logger.info,
logger.warning,)
Expand Down Expand Up @@ -72,12 +74,12 @@ def request(self, method, *args, **kwargs):
- Run the loop until the response is available
- Put requests/notifications received while waiting into a queue
If the `async` flag is present and True, a asynchronous notification is
sent instead. This will never block, and the return value or error is
ignored.
If the `async_` flag is present and True, a asynchronous notification
is sent instead. This will never block, and the return value or error
is ignored.
"""
async = kwargs.pop('async', False)
if async:
async_ = check_async(kwargs.pop('async_', None), kwargs, False)
if async_:
self._async_session.notify(method, args)
return

Expand Down
2 changes: 1 addition & 1 deletion neovim/plugin/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, nvim):
self._decode_default = IS_PYTHON3

def _on_async_err(self, msg):
self.nvim.err_write(msg, async=True)
self.nvim.err_write(msg, async_=True)

def start(self, plugins):
"""Start listening for msgpack-rpc requests and notifications."""
Expand Down
2 changes: 1 addition & 1 deletion test/test_client_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def request_cb(name, args):
vim.stop_loop()

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

Expand Down
6 changes: 3 additions & 3 deletions test/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def test_receiving_events():
@with_setup(setup=cleanup)
def test_sending_notify():
# notify after notify
vim.command("let g:test = 3", async=True)
vim.command("let g:test = 3", async_=True)
cmd = 'call rpcnotify(%d, "test-event", g:test)' % vim.channel_id
vim.command(cmd, async=True)
vim.command(cmd, async_=True)
event = vim.next_message()
eq(event[1], 'test-event')
eq(event[2], [3])

# request after notify
vim.command("let g:data = 'xyz'", async=True)
vim.command("let g:data = 'xyz'", async_=True)
eq(vim.eval('g:data'), 'xyz')


Expand Down

0 comments on commit d53415d

Please sign in to comment.