Skip to content

Prefer *-stubs when finding packages #1967

@Boon-in-Oz

Description

@Boon-in-Oz

Hi, this is going to be a hand-wavy issue, sorry.

I'm excited to try ty over Pylance in VS Code. I've immediately run into an issue though.

I run VS Code, and my module, in a Rez environment. I have a wrapped C++ package (a binary called ape.pyd) that I use a lot, which has custom stubs package called ape-stubs. In the Rez environment, PYTHONPATH contains the directories for both the package containing the ape.pyd, and the directory containing ape-stubs, but the pyd directory comes first.

With Pyright/Pylance this used to work. ape-stubs was used for autocompletion etc. However ty appears to be using ape.pyd, and it's not finding any of the useful information in the stubs.

I set the log level to "trace" and saw this in the output (I'm filtering by "ape", and I've condensed the file paths. Also as you can see I have a directory junction from C to S):

2025-12-17 10:22:04.872486000 DEBUG ty:main ty_project::metadata::options: Adding `c:\path_to_pyd\packages\ape\1.0\python-3.10` from the `PYTHONPATH` environment variable to `extra_paths`
2025-12-17 10:22:04.872533100 DEBUG ty:main ty_project::metadata::options: Adding `c:\path_to_stubs` from the `PYTHONPATH` environment variable to `extra_paths`
...
2025-12-17 10:22:04.876326600 DEBUG ty:main ty_python_semantic::module_resolver::resolver: Adding extra search-path `S:\path_to_pyd\packages\ape\1.0\python-3.10`
2025-12-17 10:22:04.876435300 DEBUG ty:main ty_python_semantic::module_resolver::resolver: Adding extra search-path `S:\path_to_stubs`
...
2025-12-17 10:22:04.882233300 DEBUG ty:main ruff_db::files::file_root: Adding new file root 'S:\path_to_pyd\packages\ape\1.0\python-3.10' of kind LibrarySearchPath
2025-12-17 10:22:04.882242200 DEBUG ty:main ruff_db::files::file_root: Adding new file root 'S:\path_to_stubs' of kind LibrarySearchPath
...
2025-12-17 10:22:04.885231400 DEBUG ty:main ty_python_semantic::module_resolver::resolver: Adding editable installation to module resolution path S:\path_above_stubs
2025-12-17 10:22:04.885242800 DEBUG ty:main ruff_db::files::file_root: Adding new file root 'S:\path_above_stubs' of kind LibrarySearchPath

I think the language server should see that it has a package called ape in a search path, and ape-stubs in a later search path, and prefer ape-stubs even though it found ape first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingimportsModule resolution, site-packages discovery, import-related diagnostics

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions