-
Notifications
You must be signed in to change notification settings - Fork 766
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Feature request: expand pylance to support IPython syntax (magics, etc). #1879
Comments
@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? |
That is correct in jupyter notebook files, but not for |
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. |
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
|
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 |
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; |
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 |
@judej we need to discuss and decide how to support this in python sync meeting. |
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. |
@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. |
An Example of this occurring with ipython-sql |
@heejaechang @judej Any insights or comments? |
@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. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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?
The text was updated successfully, but these errors were encountered: