Skip to content

torch.Tensor.ndim is not typed #42908

@KKawamura1

Description

@KKawamura1

🐛 Bug

import torch

a = torch.Tensor().ndim  # mypy says: `error: "Tensor" has no attribute "ndim"`

Environment

torch 1.6.0 and master (ecb9e79)

Why this occurs and how to solve

#38157 removed torch/__init__.pyi.in and introduced torch/_C/__init__.pyi.in, but some methods defined in torch/__init__.pyi.in (ndim, T, and grad_fn) was not salvaged and had gone away.
T and grad_fn was rescued in #40658. Only the ndim is still not typed.

The solution wolud be just adding ndim attribute to _TensorBase in torch/_C/__init__.pyi.in.

cc @ezyang @malfet @rgommers

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: typingRelated to mypy type annotationstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions