未验证 提交 45de9312 编写于 作者: W wuhuanzhou 提交者: GitHub

[cherry-pick]fix hasattr(paddle.fluid.ir.PassDesc.OP, '__name__') error (#36294)

对于__getattr__重载后不满足条件的参数,全部抛出AttributeError异常,达到与未重载版本一致。

(cherry picked from PR #36229)
上级 70e67843
...@@ -230,9 +230,6 @@ class PassDesc(object): ...@@ -230,9 +230,6 @@ class PassDesc(object):
self._type = type self._type = type
def __getattr__(self, name): def __getattr__(self, name):
if self._type is not None:
raise AttributeError(
"type object 'OpHelper' has no attribute '{}'".format(name))
op = PassDesc.OpHelper(name) op = PassDesc.OpHelper(name)
op.Init() op.Init()
return op return op
...@@ -261,7 +258,12 @@ class PassDesc(object): ...@@ -261,7 +258,12 @@ class PassDesc(object):
self._op_idx = len(block.ops) self._op_idx = len(block.ops)
self._op_desc = block.desc.append_op() self._op_desc = block.desc.append_op()
self._op_desc.set_type(self._type) self._op_desc.set_type(self._type)
self._op_proto = OpProtoHolder.instance().get_op_proto(self._type) self._op_proto = OpProtoHolder.instance().op_proto_map.get(
self._type)
if self._op_proto is None:
raise AttributeError(
"type object 'OpHelper' has no attribute '{}'".format(
self._type))
block.ops.append(self) block.ops.append(self)
def Attr(self, name): def Attr(self, name):
......
...@@ -123,6 +123,9 @@ class TestGeneratePass(unittest.TestCase): ...@@ -123,6 +123,9 @@ class TestGeneratePass(unittest.TestCase):
op_dicts[op.type] = [op] op_dicts[op.type] = [op]
return op_dicts return op_dicts
def test_has_attr(self):
self.assertFalse(hasattr(ir.PassDesc.OP, '__name__'))
def test_generate_fc_fuse(self): def test_generate_fc_fuse(self):
def _check_fc_fuse_pass(pass_desc, with_relu): def _check_fc_fuse_pass(pass_desc, with_relu):
pattern_op_dicts = self.convert_ops_to_op_dicts( pattern_op_dicts = self.convert_ops_to_op_dicts(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册