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

Pyflakes (pyls) fails when '%' is present in notebook code #281

Closed
krassowski opened this issue Jun 13, 2020 · 8 comments · Fixed by #293
Closed

Pyflakes (pyls) fails when '%' is present in notebook code #281

krassowski opened this issue Jun 13, 2020 · 8 comments · Fixed by #293
Labels
bug Something isn't working

Comments

@krassowski
Copy link
Member

Description

A weird one. Pyflakes does not work if '%' is present in code (but it is ok in comments).

I would say this is an upstream issue (of pyflakes or pyls) but it does work in plain python files - only not in notebooks.

Reproduce

lsp-percent-pyflakes

Context

  • Operating System and version: Ubuntu 20.04
  • Browser and version: Chrome
  • JupyterLab version: 2.1
python-language-server==0.31.7
pyflakes==2.1.1
jupyter-lsp==0.8.0

@krassowski
Copy link
Member Author

To be more clear: pycodestyle works ok...

Screenshot from 2020-06-14 00-53-53

@bollwyvl
Copy link
Collaborator

Dunno... something in the document rewriting? What ends up in your .virtual_document when this goes bad?

@bollwyvl
Copy link
Collaborator

Yerp, just ran into this: it's definitely some missing ^ in patterns like this one:
https://github.com/krassowski/jupyterlab-lsp/blob/master/packages/jupyterlab-lsp/src/magics/defaults.ts#L65

@bollwyvl
Copy link
Collaborator

ah, i guess % can appear anywhere on a line... and indeed, magics can be registered with any string imaginable, so long as it doesn't start with a whitespace. This is going to be tricky.

perhaps just demanding ^|\s before it would clean up some of these cases...

@krassowski
Copy link
Member Author

We can also access the CodeMirror token which is used for highlighting (string/comment/variable etc), but then we are going for a solution which would only work in some frontends.

I like the proposed regex but ^|\s would fail on x =%ls. So ^|\s|=.

However, parentheses, brackets and +/-/*/\ are not supported: x = (%ls), and x - %ls rise SyntaxError. This could potentially change in the future though... Probably would be good to consult the IPython implementation/ping someone who maintains magics to learn if they wish to keep it simple or expand the capabilities in the future.

This definitely needs some more unit tests.

@bollwyvl
Copy link
Collaborator

bollwyvl commented Jun 17, 2020 via email

@krassowski
Copy link
Member Author

Did some short digging and on the IPython side they do not have a regular expression for that now - they use tokens (not sure which tokenizer, but will definitely differ from CodeMirror) and have a special case for assignments.

I think we can go with the improved regexpr for now (for a release ETA this weekend), and think about a better way of transforming documents afterwards.

@krassowski krassowski added the bug Something isn't working label Jul 19, 2020
@krassowski
Copy link
Member Author

Obviously, even with the improved regex, it will be still possible to break things: list(" %ls")list(" get_ipython().run_line_magic("ls")", "")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants