Skip to content

False positive for torch.register_* #3988

Description

@AdrianSosic

Describe the Bug

Hi, I'm not sure if this is a false positive or if this is even supposed to be handled by static type checking, but I'm wondering how to handle the following situation:

import torch
from torch import nn


class LeModule(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.register_buffer("le_tensor", torch.tensor([0, 1, 2]))


m = LeModule()
if m.le_tensor is not None:
    result = m.le_tensor.tolist()  # pyrefly: Expected a callable, got Tensor

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.typechecking

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions