[Python] How to tell pylance to correctly read identifiers loaded by their full module name?

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    I have a file that depends on a tool from another directory. The structure is:

    • my_subproject
      • util
        • __init__.py
        • my_tool.py
      • __init__.py
      • my_main_file.py

    my_tool.py may contain something like:

    class MyTool:
    pass


    In the main file, I import it by:

    import my_subproject.util.my_tool

    my_tool_instance = my_subproject.util.my_tool.MyTool()



    This works fine when ran in python, but I suspect there are path configurations I am not aware of. I am trying to get it to work in the IDE as well.

    Right now, it says:


    "my_tool" is not a known attribute of module "my_subproject.my_util"
    ​

    In the VS Code settings for pylance, I have this:

    "python.autoComplete.extraPaths": [
    "my_subproject"
    ],
    "python.analysis.include": ["my_subproject/**"],

    Continue reading...

Compartilhe esta Página