2

I'm trying to learn how to use imports in python properly, but my linter pyright in neovim is giving me error messages despite being able to run the code. I have this structure in a python 3 test project.

directory structure

__init__.py
main.py
subdir1
  __init__.py
  test1.py
  test2.py

the init-files are empty.

main.py

from subdir1.test2 import print_message_2
print_message_2()

test1.py

def print_message():
    print(__name__)

test2.py

# this line gives linting error: "Import "subdir1.test1" could not be resolved [Pyright: reportMissingImports]"
from subdir1.test1 import print_message

def print_message_2():
    print_message()

question

How do I use python imports the right way, so that the linter doesn't complain? Is it even possible to open the test2.py file and not get linting errors?

dekuShrub
  • 466
  • 4
  • 20
  • How did you install your _pyright_? Please, share your lsp config. It may be a state where python which launches _pytright_ and the one that actually launchers your files are different. – Monsieur Merso Dec 01 '22 at 15:05
  • Where do I find my lsp config? I ghink that pyright was just installed as a dependency with conqueror of completion, but I'm not sure. – dekuShrub Dec 10 '22 at 13:06
  • Ok, I see, I've never used coq, sorry, won't be able to help. – Monsieur Merso Dec 11 '22 at 15:14

0 Answers0