basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

uv workspace imports work with pyright but not basedpyright

Open aedify-swi opened this issue 8 months ago • 4 comments

Description

Hello!

First of all, thanks for all your efforts. This is a great project!

I am trying to migrate our single-src folder layout to uv workspaces. Unfortunately, basedpyright is not able to discover the local workspace packages, while pyright is. I tried different config options that looked related, but was not able to figure it out.

I created a repo with a minimal setup. Switching the basedpyright vscode extension to pyright shows, that pyright is able to import the workspace packages.

basepyright version = "1.28.1"

Example setup: clone repo, run uv sync --all-packages and apps/bpr-rest/main.py shows the following error:

Import "bpr_core" could not be resolvedbasedpyright[reportMissingImports](https://docs.basedpyright.com/v1.28.1/configuration/config-files/#reportMissingImports)

It would be great, if you could take a look at this. Thank you for your time!

aedify-swi avatar Mar 06 '25 11:03 aedify-swi

looks like you just have to restart the language server after running uv sync --all-packages. i was able to reproduce this on both pyright and basedpyright and restarting the language server seems to fix it

DetachHead avatar Mar 16 '25 00:03 DetachHead

You are right. Restarting it, solves the issue. I could have sworn that I did that before creating this issue, but it seems I did not. I'm sorry. Thank you for your effort!

(I was a little confused that restart language server in vscode is not under python: when using basepyright.)

aedify-swi avatar Mar 31 '25 07:03 aedify-swi

come to think of it i don't see why you should have to restart the language server at all. the file watcher seems to detect when new dependencies are added without having to restart the language server, but not when new .pth files are added

DetachHead avatar Mar 31 '25 11:03 DetachHead

(I was a little confused that restart language server in vscode is not under python: when using basepyright.)

i rebranded everything mainly to prevent conflicts for users who want to use both pylance and basedpyright at the same time. this made sense early on when we didn't have as many pylance features as we do now

DetachHead avatar Mar 31 '25 11:03 DetachHead

When I use basedpyright within a uv workspace it's confused about imports.

If I have it locally installed in a child package/app in a uv workspace and try to run typechecking uv run basedpyright . from the root it won't respect the import resolution.

For example, if I have a child app foo that imports bar it will claim bar import cannot be resolved. If I run it from within bar it cannot resolve basedpyright which is weird.

lib_bar/run.py # imports bar
lib_zed/run.py # import xyz
pyproject.toml # workspace

All my other tools work as expected and correctly resolve imports i.e ruff, pytest, etc.

If I use mypy it doesn't work from the root (claims a bunch of imports can't be resolved) but when run from the leaf package, it works as expected.

EDIT: it seems to work like mypy as long as there isn't nesting actually e.g. some_dir/apps/<package> causes problems but apps/<package> works like mypy

MichaelrMentele avatar Nov 07 '25 15:11 MichaelrMentele

it's hard to reproduce without a complete example. what does the whole project structure look like? ie. what is foo, bar and xyz and where are they located?

DetachHead avatar Nov 08 '25 02:11 DetachHead