Unverified Commit d9541783 authored by pengcheng888's avatar pengcheng888 Committed by GitHub
Browse files

Merge pull request #858 from pengcheng888/issue/850

issue/850 - Tensor和device类访问不存在的属性,则抛出异常
parents ed04d3e6 1e84d3a4
...@@ -34,7 +34,10 @@ class device: ...@@ -34,7 +34,10 @@ class device:
def __getattr__(self, name): def __getattr__(self, name):
# Lazily construct and cache an attribute. # Lazily construct and cache an attribute.
# such as, self._underlying . # such as, self._underlying .
setattr(self, name, device._to_infinicore_device(self.type, self.index)) if name == "_underlying":
setattr(self, name, device._to_infinicore_device(self.type, self.index))
else:
raise AttributeError("{!r} object has no attribute {!r}".format(self, name))
return getattr(self, name) return getattr(self, name)
def __repr__(self): def __repr__(self):
......
...@@ -42,6 +42,11 @@ class Tensor: ...@@ -42,6 +42,11 @@ class Tensor:
getattr(self._underlying, name) getattr(self._underlying, name)
), ),
) )
else:
raise AttributeError(
"{!r} object has no attribute {!r}".format(__name__, name)
)
return getattr(self, name) return getattr(self, name)
@property @property
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment