Repository navigation
Conversation
…` type-checker errors
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/meta-pytorch/torchcodec/1786
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Sorry I don't think we'll do this. I still don't get why type checkers try their hardest to invalidate perfectly fine code. |
|
TBH I also find it strange that type-checkers behave this way. But many people rely on these type-checkers to prevent bugs in their code. Right now, that doesn't work for torchcodec, at all. |
I believe their main argument is that for modules with many imports, you often don't intend to expose those imports as public interface. If type-checkers treat each import as externally visible, then IDE features like import autocompletion would become very prone to importing stuff not meant to be imported, e.g. And FWIW: torch itself also uses this convention: https://github.com/pytorch/pytorch/blob/dd26d1703bfefdd03d1363f50052b5146253e734/torch/nn/__init__.py#L2-L17 |
Hi there,
Pyright does consider the
from x import ximports in__init__.pyas public interface, causing it to report errors when attempting to import fromtorchcodecor any of the subpackes. For example:Here, pyright reports:
Simiarly with
mypy --strict:Type-checking aside, measuring type coverage also doesn't work right now:
$ uvx pyrefly coverage check --public-only src/torchcodec INFO type coverage 100.00% (0 of 0 typable)(note the "0 of 0 typable")
I saw in #1443 that
__all__wasn't a desired solution, which I think is fair. So instead, I went with theimport x as xre-export approach, which is officially supported by Python's typing spec, and understood by all major static type-checkers. PyTorch itself also uses this convention: https://github.com/pytorch/pytorch/blob/dd26d1703bfefdd03d1363f50052b5146253e734/torch/nn/__init__.py#L2-L18With this fix, pyright and mypy no longer report errors for the example above, and
pyrefly coverage --public-onlynow "sees" 291 typables instead of 0.