!26805 Revert "Add the check of function return None."

Merge pull request !26805 from Margaret_wangrui/return_none
This commit is contained in:
i-robot 2021-11-26 01:28:46 +00:00 committed by Gitee
commit bbe9606f1c
4 changed files with 12 additions and 25 deletions

View File

@ -480,16 +480,6 @@ FunctionBlockPtr Parser::ParseReturn(const FunctionBlockPtr &block, const py::ob
return_expr_node = HandleInterpret(block, return_expr_node, value_object);
// Create the `return` CNode.
auto func_graph = block->func_graph();
if (IsValueNode<None>(return_expr_node)) {
py::list ret = ast_->CallParserObjMethod(PYTHON_PARSE_GET_LOCATION, node);
const auto min_list_size = 2;
if (ret.size() < min_list_size) {
MS_LOG(EXCEPTION) << "list size:" << ret.size() << " is less than 2.";
}
py::str desc =
python_adapter::CallPyModFn(ast_->module(), PYTHON_MOD_GET_OBJECT_DESCRIPTION, ast_->function(), ret[0], ret[1]);
MS_EXCEPTION(TypeError) << "Function should not 'Return None', is located in:" << desc.cast<std::string>();
}
CNodePtr return_cnode = func_graph->NewCNodeInOrder({NewValueNode(prim::kPrimReturn), return_expr_node});
func_graph->set_return(return_cnode);
return block;

View File

@ -61,10 +61,9 @@ class NetMissConstruct(nn.Cell):
def test_net_without_construct():
""" test_net_without_construct """
with pytest.raises(TypeError, match="Function should not 'Return None'"):
net = NetMissConstruct()
inp = Tensor(np.ones([1, 1, 32, 32]).astype(np.float32))
_cell_graph_executor.compile(net, inp)
net = NetMissConstruct()
inp = Tensor(np.ones([1, 1, 32, 32]).astype(np.float32))
_cell_graph_executor.compile(net, inp)
class NetWithRaise(nn.Cell):

View File

@ -192,8 +192,7 @@ def test_missing_construct():
def construct1(self, inp):
return 5
with pytest.raises(TypeError, match="Function should not 'Return None'"):
np_input = np.arange(2 * 3 * 4).reshape((2, 3, 4)).astype(np.bool_)
tensor = Tensor(np_input)
net = NetMissConstruct()
assert net(tensor) is None
np_input = np.arange(2 * 3 * 4).reshape((2, 3, 4)).astype(np.bool_)
tensor = Tensor(np_input)
net = NetMissConstruct()
assert net(tensor) is None

View File

@ -14,7 +14,7 @@
# ============================================================================
""" test super"""
import numpy as np
import pytest
import mindspore.nn as nn
from mindspore import Tensor
from mindspore import context
@ -104,11 +104,10 @@ def test_mul_super():
def test_super_cell():
with pytest.raises(TypeError, match="Function should not 'Return None'"):
net = Net(2)
x = Tensor(np.ones([1, 2, 3], np.int32))
y = Tensor(np.ones([1, 2, 3], np.int32))
assert net(x, y) is None
net = Net(2)
x = Tensor(np.ones([1, 2, 3], np.int32))
y = Tensor(np.ones([1, 2, 3], np.int32))
assert net(x, y) is None
def test_single_super_in():