Skip to content

from torch import Tensor incorrectly marked as implicit-reexport. #4424

Description

@dillydill123

Describe the Bug

from torch import Tensor

pyrefly 1.2.0 produces the following:

$ pyrefly check --preset all example.py
ERROR `Tensor` is not exported from module `torch` [implicit-reexport]
 --> example.py:1:19
  |
1 | from torch import Tensor
  |                   ^^^^^^
  |
  `Tensor` is imported by `torch` but not re-exported (via `import ... as Tensor`, `__all__`, or a wildcard import)
 INFO 1 error

torch/__init__.py does include Tensor in __all__ at the beginning of the file:

__all__ = [
    ...
    "Tensor",
    ...
]

But then has the following import in the middle of the file (1900 lines down):

from torch._tensor import Tensor  # usort: skip

My guess is that the order of __all__ and this import is causing pyrefly to incorrectly mark it as implicit.

Sandbox Link

No sandbox due to torch

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Labels

help wantedLarger than "good first issue", but still well-defined and ready for someone to pick uptypechecking

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions