That is a Pylance error.
You can create a pyrightconfig.json file at the root of your workspace and define the files to be exclude
-d from analysis or completely ignore
-d:
{
"ignore": [
"**/*.ipynb",
],
}
You can even list up specific filenames:
{
"ignore": [
"notimportant.ipynb",
"test.ipynb",
],
}
Historical Notes:
It initially didn't work for Jupyter Notebooks (.ipynb
):
https://github.com/microsoft/pylance-release/issues/2135
This happens because pyright doesn't see the file as a "*.ipynb". The file is being preprocessed (to combine all of the cells) in the notebook by the VS Code Python extension, and the resulting combined file is then passed to pyright for analysis.
The pylance team is actively working on changing the way this works. I'm going to transfer this bug to the pylance-release repo so it gets the attention it deserves.
That Github issue has since been resolved the fix was deployed as part of pylance 2022.8.51:
https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#2022851-31-august-2022-prerelease
Notable changes:
If it somehow still does not work, check the version of pylance on your VS Code.