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

Yapf escapes single quotes #786

Closed
tilsche opened this issue Nov 4, 2016 · 8 comments
Closed

Yapf escapes single quotes #786

tilsche opened this issue Nov 4, 2016 · 8 comments

Comments

@tilsche
Copy link

tilsche commented Nov 4, 2016

Using yapf on the following cell

x = "foo" + 'bar'
# 'Also in comments'

Results in:

x = "foo" + \'bar\'
# \'Also in comments\'

Further,

y = "'"

Yields a:

Error in code: SyntaxError
EOL while scanning string literal (, line 1)

Note: The command line yapf does not show any of these issues.

@jcb91
Copy link
Member

jcb91 commented Nov 4, 2016

yep, this isn't a problem with the yapf package, but with the client-side javascript escaping/unescaping that gets done. I've started a fix for this already, but not published it, will try to get around to it today...

@tilsche
Copy link
Author

tilsche commented Nov 4, 2016

BTW I just noticed that "code_prettify" does not suffer the same issues. It seems to also use yapf for python.

@jfbercher
Copy link
Member

I can't reproduce.

Both examples work for me correctly with code_prettify.

The yapf_ext was the first, early, attempt to provide a code prettifier for the jupyter notebook. I have shortly renamed it into code_prettify when adding the ability to also reformats R and javascript code. Since it builds on the earlier yapf_ext, it also uses yapf under the hood.
Indeed there were (and may remain, despite the efforts put on it) problems with quotes, special characters that were escaped during the conversion, but actually the current code_prettify version (seems to) works.

I imagine that you have installed a version of the nbextensions where yapf_ext was still present and a later version where it was replaced by code_pretiffy, where the new install still left the old yapf_ext extension directory. You may safely delete this directory.

@jcb91
Copy link
Member

jcb91 commented Nov 4, 2016

oh, apologies all, I seem to have jumped the gun. As @jfbercher says, it seems you have an earlier bersion, so an upgrade should do the trick!

@tilsche
Copy link
Author

tilsche commented Nov 4, 2016

Yes, I did install the yapf_ext from the merge request before. I tried everything to uninstall it but it seems I failed - so after installing the jupyter_contrib_nbextensions, I didn't use an updated version, but still the old one.

code_prettify works, sorry for the confusion.

@tilsche tilsche closed this as completed Nov 4, 2016
@jfbercher
Copy link
Member

No problem.
We are happy to share things that are useful and used!

@jcb91
Copy link
Member

jcb91 commented Nov 4, 2016

@tilsche

I tried everything to uninstall it but it seems I failed

This is probably because of the rename from yapf_ext to code_prettify - you'd need to run the jupyter contrib nbextension uninstall from the old version to get the uninstall to remove the old yapf_ext, as the new one only knows about code_prettify. Alternatively you could directly uninstall using the upstream notebook machinery and the nbextension's require path:

jupyter nbextension uninstall 'yapf_ext/yapf_ext'

plus whichever of the --user, --sys-prefix and --system flags you may have used. @jfbercher the uninstall of the old require path is something we could (should?) add to the jupyter contrib nbextension migrate command?

@jfbercher
Copy link
Member

@jfbercher the uninstall of the old require path is something we could (should?) add
to the jupyter contrib nbextension migrate command?

Yes, probably.
This issue shows that we have to uninstall old extensions when we rename/remove them from the repo (perhaps shall we put these uninstall steps in the contrib nbextension install step, to remove older/outdated versions?)

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

No branches or pull requests

3 participants