forked from mindspore-Ecosystem/mindspore
!26805 Revert "Add the check of function return None."
Merge pull request !26805 from Margaret_wangrui/return_none
This commit is contained in:
commit
bbe9606f1c
|
@ -480,16 +480,6 @@ FunctionBlockPtr Parser::ParseReturn(const FunctionBlockPtr &block, const py::ob
|
||||||
return_expr_node = HandleInterpret(block, return_expr_node, value_object);
|
return_expr_node = HandleInterpret(block, return_expr_node, value_object);
|
||||||
// Create the `return` CNode.
|
// Create the `return` CNode.
|
||||||
auto func_graph = block->func_graph();
|
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});
|
CNodePtr return_cnode = func_graph->NewCNodeInOrder({NewValueNode(prim::kPrimReturn), return_expr_node});
|
||||||
func_graph->set_return(return_cnode);
|
func_graph->set_return(return_cnode);
|
||||||
return block;
|
return block;
|
||||||
|
|
|
@ -61,7 +61,6 @@ class NetMissConstruct(nn.Cell):
|
||||||
|
|
||||||
def test_net_without_construct():
|
def test_net_without_construct():
|
||||||
""" test_net_without_construct """
|
""" test_net_without_construct """
|
||||||
with pytest.raises(TypeError, match="Function should not 'Return None'"):
|
|
||||||
net = NetMissConstruct()
|
net = NetMissConstruct()
|
||||||
inp = Tensor(np.ones([1, 1, 32, 32]).astype(np.float32))
|
inp = Tensor(np.ones([1, 1, 32, 32]).astype(np.float32))
|
||||||
_cell_graph_executor.compile(net, inp)
|
_cell_graph_executor.compile(net, inp)
|
||||||
|
|
|
@ -192,7 +192,6 @@ def test_missing_construct():
|
||||||
def construct1(self, inp):
|
def construct1(self, inp):
|
||||||
return 5
|
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_)
|
np_input = np.arange(2 * 3 * 4).reshape((2, 3, 4)).astype(np.bool_)
|
||||||
tensor = Tensor(np_input)
|
tensor = Tensor(np_input)
|
||||||
net = NetMissConstruct()
|
net = NetMissConstruct()
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
""" test super"""
|
""" test super"""
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
|
||||||
import mindspore.nn as nn
|
import mindspore.nn as nn
|
||||||
from mindspore import Tensor
|
from mindspore import Tensor
|
||||||
from mindspore import context
|
from mindspore import context
|
||||||
|
@ -104,7 +104,6 @@ def test_mul_super():
|
||||||
|
|
||||||
|
|
||||||
def test_super_cell():
|
def test_super_cell():
|
||||||
with pytest.raises(TypeError, match="Function should not 'Return None'"):
|
|
||||||
net = Net(2)
|
net = Net(2)
|
||||||
x = Tensor(np.ones([1, 2, 3], np.int32))
|
x = Tensor(np.ones([1, 2, 3], np.int32))
|
||||||
y = Tensor(np.ones([1, 2, 3], np.int32))
|
y = Tensor(np.ones([1, 2, 3], np.int32))
|
||||||
|
|
Loading…
Reference in New Issue