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

Tolerance of ipython cell magics in source code cells #1497

Closed
rben01 opened this issue Sep 12, 2018 · 7 comments
Closed

Tolerance of ipython cell magics in source code cells #1497

rben01 opened this issue Sep 12, 2018 · 7 comments
Labels
bug Issue identified by VS Code Team member as probable bug notebook-intellisense Intellisense & other language features in notebook cells for any language

Comments

@rben01
Copy link

rben01 commented Sep 12, 2018

Environment data

  • VS Code version: 1.27.1
  • Extension version: 2018.8.0
  • OS and version: macOS 10.14
  • Python version: Anaconda Python 3.6
  • Type of virtual environment used: conda
  • Relevant/affected Python packages and their versions: N/A

Actual behavior

When using a python file as a makeshift Jupyter notebook (with use of the VSCode Jupyter extension), valid ipython kernel code is flagged as invalid by the Python parser. For instance, cell magics, which begin with one or two percent signs, are flagged as syntax errors

Expected behavior

The parser should ignore valid ipython cell magic syntax; flagging these as problems just adds noise. A good solution might be to have the Python extension have its own internal Jupyter flag, which when enabled would understand that ipython cell magics are syntactically correct, but when disabled would treat the file as vanilla Python for the purpose of checking syntax.

Steps to reproduce:

Write e.g., %matplotlib inline at the top of the file.

@brettcannon
Copy link
Member

FYI there is a way to turn off the syntax errors (the docs are in the process of being written and I'm pressed for time, else I would look it up for you).

@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 13, 2020
@DonJayamanne
Copy link
Contributor

Moving back to new issues to triage.
We can contribute to pylance & jedi or just swallow these messages from the middle man.

@rben01
Copy link
Author

rben01 commented Mar 25, 2021

I think this can be closed, as it looks like the python extension now supports this via comments that begin with #!, e.g.,

#! %matplotlib inline

EDIT: I think #3263 contains more details.

@rebornix
Copy link
Member

I wonder if we should filter out these set of errors in the notebook language client middleware, @rchiodo do you think that's the right layer?

@rchiodo
Copy link
Contributor

rchiodo commented Jul 28, 2021

@rebornix, yes I think so. I believe we have another issue we're we recommended just that:

#6635

@rchiodo rchiodo closed this as completed Jul 28, 2021
@rchiodo rchiodo reopened this Jul 28, 2021
@rchiodo
Copy link
Contributor

rchiodo commented Jul 28, 2021

Sorry closed prematurely. This issue is I believe about magics in python files, not notebooks. Python files would not be handled by the middleware piece we have. Although maybe we'd do something similar.

@rebornix rebornix added this to the August 2021 milestone Jul 29, 2021
@rebornix rebornix self-assigned this Jul 29, 2021
@greazer greazer added language-python notebook-intellisense Intellisense & other language features in notebook cells for any language labels Aug 5, 2021
@rchiodo
Copy link
Contributor

rchiodo commented Aug 30, 2021

Closing for now as the workaround described above should work. Otherwise we'd have to special case python files with cell markers.

@rchiodo rchiodo closed this as completed Aug 30, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug notebook-intellisense Intellisense & other language features in notebook cells for any language
Projects
None yet
Development

No branches or pull requests

6 participants