Feature request: expand pylance to support IPython syntax (magics, etc). #2582
Replies: 15 comments 7 replies
-
@ryan-feeley Unless I'm mistaken, the Python/Jupyter extension should already be ignoring diagnostics for lines with magic on them. Is that not the case? |
Beta Was this translation helpful? Give feedback.
-
That is correct in jupyter notebook files, but not for |
Beta Was this translation helpful? Give feedback.
-
I haven't heard of There's special handling for notebooks for these IPython specific things, but these The Python/Jupyter extension IIRC support an "interactive mode", where these special directives are in comments instead, as an alternative for the time being. |
Beta Was this translation helpful? Give feedback.
-
VS Code automatically associates the Python language mode with There are two flavors of IPython, one is the two process IPython kernel / frontend that is used by the To do something like
in your I suppose you could also hack it and do something like less flexible like
|
Beta Was this translation helpful? Give feedback.
-
I get that this support might not be a near-term priority on your roadmap. It's just an FYI that the Pylance language server, which is also sort of playing the role of a linter, is flagging code that other linters which are aware of |
Beta Was this translation helpful? Give feedback.
-
Pylance is a static analyzer for code only, and doesn't manage running code or anything, so I'm not too worried about that side. I'm a bit surprised that VS Code would do this, but indeed it does: https://github.com/microsoft/vscode/blob/main/extensions/python/package.json#L27 All of the other files listed share the same Python grammar; |
Beta Was this translation helpful? Give feedback.
-
Thanks for digging into it. Yeah, it is a bit weird... But it's the nature of how some of these tools evolved over the years. It's mostly an issue in data science. If you doing actual software engineering, you wouldn't be just using grammar extensions willy-nilly. But if you're coming over from like PyCharm or Spyder which have always supported IPython magics, or from matlab, which has it's own magic, you might expect it to work. I'm not sure you need to parse the grammar. Maybe just ignore it? By its very nature, these magics are sort of slip-streaming stuff in to the background that you probably don't need to be aware of. The "cell magic" syntax |
Beta Was this translation helpful? Give feedback.
-
@judej we need to discuss and decide how to support this in python sync meeting. |
Beta Was this translation helpful? Give feedback.
-
https://github.com/microsoft/pyrx/pull/2146 adds support for ipython magic in ipynb file. no support for ipy yet. any line with % in ipynb will be treated as non python code and ignored for now. no, intellisense support on magic line yet. |
Beta Was this translation helpful? Give feedback.
-
@heejaechang @judej Is this for line magics only or does it also ignore cell magics? A cell magic is similar to a line magic except that it starts with %% and has multiple lines. For example:
It would be great to have cell magics support, too, as I am currently developing a cells magic, and all the hints from the Python linter are really disturbing. |
Beta Was this translation helpful? Give feedback.
-
An Example of this occurring with ipython-sql |
Beta Was this translation helpful? Give feedback.
-
@heejaechang @judej Any insights or comments? |
Beta Was this translation helpful? Give feedback.
-
@timoklimmer, sorry no update as yet. We are working on updating our notebooks implementation and will be able to look at magics soon after that. Moving this issue to discussion as an enhancement request for comments and upvotes. |
Beta Was this translation helpful? Give feedback.
-
@heejaechang @judej Are there any updates on the notebook implementation of Pylance? I'm specially looking forward to being able to rename symbols and use refactoring in notebooks. This was being tracked in microsoft/vscode-jupyter/issues/5123 but I was redirected here. Please let me know if this is being tracked somewhere else. |
Beta Was this translation helpful? Give feedback.
-
Is this same problem with this discussion? this code can run correctly, but there is a prompt by pylance |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Discussed in #1868
Originally posted by ryan-feeley September 23, 2021
An IPython magic statement like
%load_ext autoreload
or%timeit f()
is not valid pure python code, but it is valid IPython syntax, which one can use in the IPython shell or Jupyter notebook. These are popular development tools.I believe would be useful enhancement for pylance to avoid giving errors on such IPython line and cell magics if the underlying file type in the editor is
.ipy
(standard extension for an IPython script file) or*.ipynb
(jupyter notebook).What is the current recommended workaround for such cases? Does one add a trailing
# type: ignore
to each line? Or does one break out of the zen of ipython and do something likeIs there any plan on the roadmap for pylance to be extended to IPython syntax?
Beta Was this translation helpful? Give feedback.
All reactions