pyright 1.1.409 `reportPrivateImportUsage` on `torch.bfloat16` import
Describe the bug
Given a file like
from torch import bfloat16
Then:
me@computer $ uv tool run --with pyright==1.1.408 --with torch==2.8.0 --python 3.12 pyright client.py
0 errors, 0 warnings, 0 informations
me@computer $ uv tool run --with pyright==1.1.409 --with torch==2.8.0 --python 3.12 pyright client.py
/home/josh_cannon/client.py
/home/josh_cannon/client.py:1:19 - error: "bfloat16" is not exported from module "torch"
Import from "torch._C" instead (reportPrivateImportUsage)
I suspect this is due to https://github.com/microsoft/pyright/pull/11375, but couldn't verify precisely.
This also may just be a bug in torch (e.g. torch should define a __init__.pyi with all the names in it, a subset of which are in _C/__init__.pyi)
I'm also curious if there's a good way to silence errors like this targeted to specific usage. Kind of like warning filters in https://docs.pytest.org/en/stable/how-to/capture-warnings.html#controlling-warnings
I can confirm. Same behavior here. Started with update from 1.1.408 to 1.1.409
Seeing what I think is a related issue in Bokeh after updating to pyright 1.1.409. Both torch and Bokeh generate __all__ dynamically. I'm not sure if pyright is expected to expand these, but the imports flagged as private are populated in __all__ eventually (at least in Bokeh).
I'm getting the same behaviour. Could it also be due to https://github.com/microsoft/pyright/pull/11237 ?
This looks fixed now:
$ uv tool run --with pyright==1.1.411 --with torch==2.8.0 --python 3.12 pyright client.py
Installed 12 packages in 307ms
0 errors, 0 warnings, 0 informations
Thanks for verifying.