pyright icon indicating copy to clipboard operation
pyright copied to clipboard

pyright 1.1.409 `reportPrivateImportUsage` on `torch.bfloat16` import

Open thejcannon opened this issue 7 months ago • 6 comments

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)

thejcannon avatar Apr 23 '26 16:04 thejcannon

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

nate-england avatar Apr 23 '26 17:04 nate-england

I can confirm. Same behavior here. Started with update from 1.1.408 to 1.1.409

ClaasRostock avatar Apr 24 '26 11:04 ClaasRostock

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).

nileracecrew avatar Apr 27 '26 14:04 nileracecrew

I'm getting the same behaviour. Could it also be due to https://github.com/microsoft/pyright/pull/11237 ?

renzph avatar Apr 29 '26 11:04 renzph

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

cosinequanon avatar Jul 08 '26 18:07 cosinequanon

Thanks for verifying.

rchiodo avatar Jul 08 '26 18:07 rchiodo