Allow keeping pylance features enabled in Jupyter notebook cells with %%
magic
#3851
Replies: 6 comments 9 replies
-
If this is the next step for cell magics, we'd need to know which ones aren't expecting another language in the cell. |
Beta Was this translation helpful? Give feedback.
-
Or maybe if |
Beta Was this translation helpful? Give feedback.
-
From this IPython documentation, I'm not sure that's possible in the general case — it looks like the obvious ones would be |
Beta Was this translation helpful? Give feedback.
-
Transferred to a discussion to get up votes. |
Beta Was this translation helpful? Give feedback.
-
✅ such a feature would make the combination very powerful to teach micropython and IoT, and also would make for a simple way to experiments with different and document the results making is easy to share samples in the community, using the micropython magics other candidates for an allowlist are:
I would add that cell magics can have additional parameters following the cell magic, for instance: %% micropython connect COM7
# blink the led
from machine import Pin
led = Pin(25, Pin.OUT)
import time
for _ in range(5):
led.value(0)
time.sleep(0.25)
led.value(1)
time.sleep(0.25) for more details see: https://ipython.readthedocs.io/en/stable/config/custommagics.html#defining-custom-magics There are other partial solutions implemented that appear to only only in python , and fail to run the magics from Jupyter |
Beta Was this translation helpful? Give feedback.
-
@DonJayamanne suggested we use request forwarding and then map magics to what language they should support. The request forwarding should work for python too as we'd just forward it to ourselves. |
Beta Was this translation helpful? Give feedback.
-
There are some use cases for keeping Pylance features (type checking, semantic highlight etc.) on for Jupyter notebook cells that use
%%
magic directives (for example,%%capture
). This is sort of counter to a previous issue filed #3327.For example, if I have a cell like this:
The presence of
%%capture
seems to disable Pylance features (type checking, refactor, semantic highlight etc.) but in this case it would actually be preferable to treat everything but the magic as plain Python.I'm not sure of a perfect way to solve this generally given the
%%sql
etc. use cases above, but there are two options that I think could work:#!%%
magic in notebook cells, which was the approach taken in IPython magic commands need to be runnable from comments so other tools can work with them. vscode-jupyter#3263 but it doesn't seem to work in.ipynb
files (maybe it's just for.ipy
files?). This would allow Pylance,isort
etc. to just do their jobs easily without any special handling, I think.%%capture # type:ignore
or something along those lines, to indicate that the rest of the file should be treated as Python but ignore the%%
. This seems perhaps more compatible with the default Jupyter implementation, but more work on the Pylance side (and other tools that might need to handle it)?Originally posted by @ian-h-chamberlain in #2582 (reply in thread)
Beta Was this translation helpful? Give feedback.
All reactions