Skip to content

mypy error due to wrong typehints for tensor.cpu / tensor.cuda : missing memory_format #118501

@fzimmermann89

Description

@fzimmermann89

🐛 Describe the bug

Repost of #118386 as a bug report template:

The generated type information in pytorch/torch/_C/__init__.pyi fortensor.cpuare wrong:

def cpu(self) -> Tensor:
        r"""
        cpu(memory_format=torch.preserve_format) -> Tensor

this is caused by

pytorch/tools/pyi/gen_pyi.py

Lines 1204 to 1207 in 6da0e7f

simple_conversions = [
"byte",
"char",
"cpu",

where .cpu is added as having no parameters, which does not match the documentation or implementation

This bug causes mypy to complain about downstream usage of the memory_format parameter of Tensor.cpu.

Simiiar, .cuda is wrong here:

pytorch/tools/pyi/gen_pyi.py

Lines 1102 to 1112 in 6da0e7f

"cuda": [
"def cuda({}) -> Tensor: ...".format(
", ".join(
[
"self",
"device: Optional[Union[_device, _int, str]] = None",
"non_blocking: _bool = False",
]
)
)
],

where also memory_format is missing

Versions

main

cc @ezyang @malfet @xuzhao9 @gramster

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