basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

doesn't detect imports from implicit namespace packages (PEP 420)

Open npip99 opened this issue 10 months ago • 1 comments

Description

Currently, I have these files:

your-repo/
├── ml/
│   └── ... ml code
├── scripts/
│   └── ... scripts code
├── pyproject.toml

With pyproject.toml containing

[project]
name = "ml"
...
[tool.setuptools.packages.find]
where = ["."]
include = ["ml", "scripts"]

However, imports from the scripts directory don't typecheck correctly,

Image

At runtime, it imports fine, so it's only an issue with the typechecker.

Also, interestingly, imports from ml directory work fine, it's only an issue with the introduction of a second directory to import from. Also, executing touch ./scripts/__init__.py fixes it. But, __init__.py shouldn't be necessary based on PEP 420.

Workaround

Execute touch ./other_directory/__init__.py

Ideal

The typechecker finds the import without __init__.py

npip99 avatar Apr 23 '25 18:04 npip99

i can't reproduce this. could you provide some more info please:

  • what version of basedpyright you're using
  • is basedpyright running from the pypi package in your environment, or the version that comes bundled with the vscode extension?
  • does the same thing happen in pyright or pylance?
  • the contents of the scripts and ml directories (the ml directory doesn't seem to be used in your example at all, is it actuaally needed as part of this minimal repro?)
  • what tool(s) you're using to manage your python environment (eg. uv, pip/virtualenv, etc)

DetachHead avatar May 10 '25 05:05 DetachHead

closing this. if you are still experiencing this issue please provide the additional info mentioned above and we can re-open

DetachHead avatar Nov 08 '25 02:11 DetachHead