Improve error message when accessing attributes that don't exist (#1936)

New:
   >>> torch.autograd.Variable(torch.randn(3, 3)).foobar
   AttributeError: 'Variable' object has no attribute 'foobar'

Old:
   >>> torch.autograd.Variable(torch.randn(3, 3)).foobar
   AttributeError: foobar
This commit is contained in:
Sam Gross 2017-06-28 20:13:15 -04:00 committed by GitHub
parent 8a4eb50ed1
commit 0a95613cef

View File

@ -61,7 +61,7 @@ class Variable(_C._VariableBase):
def __getattr__(self, name):
if name in self._fallthrough_methods:
return getattr(self.data, name)
raise AttributeError(name)
return object.__getattribute__(self, name)
def __getitem__(self, key):
if torch.is_tensor(key):