Skip to content

Improve attribute missing error message. #20495

@zdevito

Description

@zdevito

When accessing a non-existent attribute on a script module, it gives the error below. It should instead say the attribute does not exist (which is different from it being None).

        class A(torch.jit.ScriptModule):
            def __init__(self):
                super(A, self).__init__()

            @torch.jit.script_method
            def forward(self, x):
                return x + self.whatisgoingon

        class B(A):
            def __init__(self):
                super(B, self).__init__()
            @torch.jit.script_method
            def bar(self, x):
                return x * x 
        
        A()
attribute 'whatisgoingon' of type 'NoneType' is not usable in a script method (did you forget to add it __constants__?):
@torch.jit.script_method
def forward(self, x):
    return x + self.whatisgoingon
               ~~~~~~~~~~~~~~~~~~ <--- HERE

Metadata

Metadata

Assignees

Labels

oncall: jitAdd this issue/PR to JIT oncall triage queue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions