0

PyCharm has this very useful warnings where it underlines/highlights any problematic code and give you hints of how to fix it, like when you hint a variable type and then you provide another type: var: int = ~"Hello World!"~. Or when you are typing a indented code, but you forget to add the colons

for i in range(3)~~
    print("Hello World!")

And also give you hints about the "cleanness" of your code to follow the PEPs, like if you type ~a=2*4~ it will tell you to write a = 2 * 4.

All this little hints seem very useful, specially for a beginner, but when I chose to use jupyter lab as my IDE, I discovered that there was almost no hints; To get the errors you have to run the code each time to check you didn't missed any vital part, and then solve one by one the problems that prevent the code from running.

I'm new, so maybe there is an option that was there and I haven't noticed, but in case there is not, is there any way to instal a warning system for Jupyter Lab, specially one that detects the two first issues.

P.D.: I apologise if the I wasn't clear, I'm not really sure about the terminology for this warnings, and thank you in advance.

  • I'm not quite familiar with JupytertLab (only notebook), but it seems it is "just" a fancy web interface, whereas PyCharm is a whole IDE with more features and runs on its own. (JupyterLab is sometimes also called IDE, but for Interactive Development Environment, normally IDE stands for Integrated Developement Environment) – mhenning Aug 27 '23 at 13:10
  • @mhenning this is incorrect, while JupyterLab can be used as a web interface (just like a number of other IDEs), it is also available as a standalone desktop app (https://github.com/jupyterlab/jupyterlab-desktop) and supports the same LSP protocol that powers linting in other editors (https://github.com/jupyter-lsp/jupyterlab-lsp). The web interface is commonly used for teaching because you can just host a JupyterHub for students and they don't need to install anything. – krassowski Aug 27 '23 at 14:49

1 Answers1

0

The jupyterlab-lsp extension includes in-code diagnostics and features a diagnostics panel:

enter image description here

The small triangle on the screenshot indicates missing colon; the triangle indicator is only available in jupyterlab-lsp 5.0 targeting JupyterLab 4.0+ which is currently in pre-release but can be installed using pip install --pre jupyterlab-lsp. This and older versions include the underlines, and other highlights (e.g. strike-through for deprecated messages).

On the screenshot above it did not detect the type issue because function was malformed (no colon), but when there is no syntax errors it highlights type issues correctly:

enter image description here

With jupyterlab-lsp you are not limited to any single implementation of the linting service - you can for example use:

  • pyright (as on screenshot) which runs in Node runtime,
  • pylsp which is pure Python and supports pyflakes, flake8, pylint, etc
  • jedi-language-server which will only highlight syntax errors but is lightweight to run and only depends on jedi package.

Since JupyterLab 4.0 some of the LSP code is shipped by default but the extension installation is required because the LSP features are opt-in.

krassowski
  • 13,598
  • 4
  • 60
  • 92