Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'SyntaxError: invalid syntax' on Python 3.7 alpha pre-release #274

Merged
merged 3 commits into from
Apr 22, 2018

Conversation

lambdalisue
Copy link
Contributor

1__tmux

Reason

'async' is keyword in Python 3.7

https://www.python.org/dev/peps/pep-0492/#deprecation-plans

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the parameter really need to be changed? That's silly, python parser should know the difference.

This will be a breaking change for our users

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I machinery replaced all async into _async so I'm not sure about this particular line.
However the screenshot I pasted showed invalid syntax on function attributes and this PR fixed that issue.

@justinmk
Copy link
Member

I guess we need to detect the python version and show a warning.

@lambdalisue
Copy link
Contributor Author

While Python 3.7 is in alpha stage yet, this PR may not required in future.
I made this PR just for note and users who need Python 3.7 support right now.

@bfredl
Copy link
Member

bfredl commented Oct 15, 2017

So let's wait until python 3.7 is at least in beta. Hopefully they will gather their senses and make it a context-dependent keyword (the pattern used by python in the past). If not, we must keep the existing async keyword for <=3.6 and and use something else for >=3.7, perhaps using a script as part of the build system.

@bfredl bfredl changed the title Fix 'SyntaxError: invalid syntax' on Python 3.7 Fix 'SyntaxError: invalid syntax' on Python 3.7 alpha pre-release Oct 15, 2017
@lioumens
Copy link

lioumens commented Mar 3, 2018

Thanks for the PR @lambdalisue. FYI python 3.7 is now in beta.

@bfredl
Copy link
Member

bfredl commented Mar 3, 2018

Is the breaking change still there? I looked into https://docs.python.org/3.7/whatsnew/3.7.html and grepped for both "async" and "keyword", and found nothing.

@Shougo
Copy link
Contributor

Shougo commented Mar 5, 2018

@bfredl https://docs.python.org/3.6/whatsnew/3.6.html#new-keywords

It is added in Python 3.6 what's new documentation.

New Keywords
async and await are not recommended to be used as variable, class, function or module names. Introduced by PEP 492 in Python 3.5, they will become proper keywords in Python 3.7. Starting in Python 3.6, the use of async or await as names will generate a DeprecationWarning.

Note: It should be added in Python 3.7 what's new though.

@justinmk
Copy link
Member

justinmk commented Mar 5, 2018

Looks like other popular projects deal with this in the same way. Though async_ (underscore at end) is more common, so let's also use async_.

@jdemilledt
Copy link

Python 3.7.0b2 still has this issue.

@lambdalisue
Copy link
Contributor Author

lambdalisue commented Apr 12, 2018

Shall I replace _async to async_?

@justinmk
Copy link
Member

@lambdalisue yes, thanks.

@lambdalisue lambdalisue force-pushed the master branch 3 times, most recently from 3b156e7 to 6d1b28b Compare April 12, 2018 21:28
@lambdalisue
Copy link
Contributor Author

lambdalisue commented Apr 12, 2018

alacritty 2018-04-13 06-29-28

Done. It seems tests are failing on master as well so I just ended-up.

Additionally, you said

I guess we need to detect the python version and show a warning.

So I added 6d1b28b c421bf5 for backward compatibility. Please revert whenever you satisfied the new API (I'm sorry I found a minor bug on 6d1b28b so I updated forcedly).

warnings.warn(
'"async" attribute is deprecated. Use "async_" instead.',
DeprecationWarning,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good solution to me.

If no one else comments, ping in a few days, then we merge.

@jdemilledt
Copy link

Looks like AppVeyor is drunk.

@justinmk
Copy link
Member

justinmk commented Apr 12, 2018

I broke master when I merged #290 , that's why travis is failing. Fixed by neovim/neovim#8265.

Restarted travis build.

@jdemilledt
Copy link

@justinmk Ping

"""Add a highlight to the buffer."""
if async is None:
async = (src_id != 0)
if async_ is None and 'async' in kwargs:
Copy link
Member

@bfredl bfredl Apr 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it can be a helper function:
async_ = check_async(async_, kwargs, (src_id != 0))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be? It's just one line and used only here so I don't think it's a good idea to extract a simple code into a helper function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How so? it is 8-9 lines unrelated to the original meaning of the function in at least three places (here, clear_highlight, and request)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got. Sorry, I thought you are talking about exactly this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 👍

@@ -13,7 +13,7 @@ class UvEventLoop(BaseEventLoop):

def _init(self):
self._loop = pyuv.Loop()
self._async = pyuv.Async(self._loop, self._on_async)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid substitution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bfredl
Copy link
Member

bfredl commented Apr 17, 2018

Other than comments, LGTM.

@@ -13,7 +13,7 @@ class UvEventLoop(BaseEventLoop):

def _init(self):
self._loop = pyuv.Loop()
self._async = pyuv.Async(self._loop, self._on_async)
self.async_ = pyuv.Async(self._loop, self._on_async)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the internal variable name, it should not change.

Always check changes after search-and-replace ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README.md (and any other docs) needs to be updated, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always check changes after search-and-replace ...

I'm sorry for that. I didn't realize that there is a private variable for async.
I'll recheck.

The README.md (and any other docs) needs to be updated, too.

Shall I? I'm not native so writing docs is a bit hard for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done by a9a3a70 Is it enough?

@lambdalisue
Copy link
Contributor Author

It seems the highlighted two lines are for private attributes so I renamed these to _async in 5718624

alacritty 2018-04-18 00-34-39

I would like to melt that commit into b7c0d12 once you satisfied that changes.

@lambdalisue
Copy link
Contributor Author

I'll melt 1626e93 into c421bf5 later 👍

@lambdalisue
Copy link
Contributor Author

Done.

@jdemilledt
Copy link

What release is this planned to be included in?

@bfredl bfredl merged commit d53415d into neovim:master Apr 22, 2018
@bfredl
Copy link
Member

bfredl commented Apr 22, 2018

Unrelated failure (I presume):

FAILED (errors=1)
Exception ignored in: <bound method BaseEventLoop.__del__ of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
  File "/opt/python/3.5.5/lib/python3.5/asyncio/base_events.py", line 511, in __del__
  File "/opt/python/3.5.5/lib/python3.5/asyncio/unix_events.py", line 65, in close
  File "/opt/python/3.5.5/lib/python3.5/asyncio/unix_events.py", line 146, in remove_signal_handler
  File "/opt/python/3.5.5/lib/python3.5/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

Merged. Thanks @lambdalisue for you work.

@bfredl
Copy link
Member

bfredl commented Apr 22, 2018

@jdemilledt 3.7 final is due to 15 june, we will have a release well before then. If I get around to it I will finish the lua PR #325 next week, and then do a release.

justinmk pushed a commit that referenced this pull request Apr 27, 2018
bfredl added a commit that referenced this pull request Apr 29, 2018
This release adds support for Python 3.7 which now is in beta. `async`
is a keyword in python3.7, and it should be replaced with `async_` when
used as a keyword argument to API methods. `async` is still supported
with python 2.7 and 3.6 for the moment, but considered deprecated.

Also, integration with the in-process lua interpreter in Nvim is now supported.

Changes since 0.2.4:

* debcde0 clean up remote object implementation (#313)
* e880fe7 Guidelines for local plugin development (#317)
* 1ab98e8 Update the working directory on DirChanged for legacy plugins (#296)
* d53415d Fix SyntaxError in py3.7: use `async_` instead of `async` (#274)
* b65f62d Use `pytest` as `nosetests` are not longer maintained (#266)
* d9aed96 Support using lua functions. `buf.update_higlights` as an internal example (#325)
mhinz added a commit to mhinz/neovim-remote that referenced this pull request Jun 28, 2018
This release adds support for Python 3.7.

Previously we didn't allow that version because python-client had problems with
it, since arguments were named after keywords newly introduced in 3.7.

Fixed since of neovim/pynvim#274
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants