Skip to content

Pyright complains about exported modules #3843

@ianliu

Description

@ianliu

Describe the bug
In some specific case, pyright will complain that "Some object" is not exported from module "X". For instance:

mkdir test && cd test
python -m venv venv
venv/bin/python -m pip install distributed==2022.8.0
echo "from distributed import Client" > foo.py
echo '{"venv":"venv"}' > pyrightconfig.json
pyright -v $PWD

To get this result:

pyright 1.1.266
/tmp/test/foo.py
  /tmp/test/foo.py:1:25 - error: "Client" is not exported from module "distributed"
    Import from "distributed.client" instead (reportPrivateImportUsage)
1 error, 0 warnings, 0 informations

To Reproduce

I've drilled the issue down to the following minimal example that doesn't depend on the distributed package:

mkdir test1 && cd test1
python -m venv venv
mkdir venv/lib/python3.10/site-packages/bar
echo "from bar.submod import Klass" > venv/lib/python3.10/site-packages/bar/__init__.py
echo "class Klass: pass" > venv/lib/python3.10/site-packages/bar/submod.py
touch venv/lib/python3.10/site-packages/bar/py.typed
echo "from bar import Klass" > foo.py
echo '{"venv":"venv"}' > pyrightconfig.json
pyright -v $PWD

Which gives:

pyright 1.1.266
/tmp/test1/foo.py
  /tmp/test1/foo.py:1:17 - error: "Klass" is not exported from module "bar"
    Import from "bar.submod" instead (reportPrivateImportUsage)

If I do any of the following actions, pyright type-checks correctly:

  • Move the bar package from the venv to the root: mv venv/lib/python3.10/site-packages/bar .
  • With the package in the venv, remove the venv/lib/python3.10/site-packages/bar/py.typed file

Expected behavior
I would expect pyright to type-check the examples above.

Additional info

The first code snippet relies on the following package versions:

click==8.1.3
cloudpickle==2.1.0
dask==2022.8.0
distributed==2022.8.0
fsspec==2022.7.1
HeapDict==1.0.1
Jinja2==3.1.2
locket==1.0.0
MarkupSafe==2.1.1
msgpack==1.0.4
packaging==21.3
partd==1.3.0
psutil==5.9.1
pyparsing==3.0.9
PyYAML==6.0
sortedcontainers==2.4.0
tblib==1.7.0
toolz==0.12.0
tornado==6.1
urllib3==1.26.11
zict==2.2.0

VS Code extension or command-line
Running pyright from the command line, version 1.1.266 installed from the Arch Linux repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions