Layout:
workspace/
.vscode/launch.json
main.py
foo.py:
def harr(): pass
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"cwd": "${workspaceFolder}/..",
"module": "${workspaceFolderBasename}"
}
]
}
main.py and pylint error:
from .foo import harr
^
Attempted relative import beyond top-level package - pylint(relative-beyond-top-level)
The program runs fine if not for the linter error. I have tried modifying sys.path in __init__.py and through pylintrc but the result is the same.
Is there a way VSCode can run linting for a file and know at the same time that the file is part of a package?
I've scanned through vscode linting and the pylint config docs but found nothing like what I'd expect. This should be so standard, what am I not getting? How is pylint supposed to work out relative imports if it has no idea of the top-level package?