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

fix hasattr(paddle.fluid.ir.PassDesc.OP, '__name__') error (#36229)

对于__getattr__重载后不满足条件的参数,全部抛出AttributeError异常,达到与未重载版本一致。
上级 57e8cbec
......@@ -230,9 +230,6 @@ class PassDesc(object):
self._type = type
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.Init()
return op
......@@ -261,7 +258,12 @@ class PassDesc(object):
self._op_idx = len(block.ops)
self._op_desc = block.desc.append_op()
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)
def Attr(self, name):
......
......@@ -123,6 +123,9 @@ class TestGeneratePass(unittest.TestCase):
op_dicts[op.type] = [op]
return op_dicts
def test_has_attr(self):
self.assertFalse(hasattr(ir.PassDesc.OP, '__name__'))
def test_generate_fc_fuse(self):
def _check_fc_fuse_pass(pass_desc, with_relu):
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.
先完成此消息的编辑!
想要评论请 注册