From 922678edefa72729773dc0a73cfab17a8b3183b5 Mon Sep 17 00:00:00 2001 From: Margaret_wangrui Date: Thu, 25 Nov 2021 18:41:20 +0800 Subject: [PATCH] Revert "Add the check of function return None." This reverts commit f9a384456af5f24774b19bf3985f5513cf6908f6. --- mindspore/ccsrc/pipeline/jit/parse/parse.cc | 10 ---------- tests/ut/python/ops/test_ops_check.py | 7 +++---- .../python/pipeline/parse/test_grammar_constraints.py | 9 ++++----- tests/ut/python/pipeline/parse/test_super.py | 11 +++++------ 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/mindspore/ccsrc/pipeline/jit/parse/parse.cc b/mindspore/ccsrc/pipeline/jit/parse/parse.cc index a777a98440e..61e39d20967 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/parse.cc +++ b/mindspore/ccsrc/pipeline/jit/parse/parse.cc @@ -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(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(); - } CNodePtr return_cnode = func_graph->NewCNodeInOrder({NewValueNode(prim::kPrimReturn), return_expr_node}); func_graph->set_return(return_cnode); return block; diff --git a/tests/ut/python/ops/test_ops_check.py b/tests/ut/python/ops/test_ops_check.py index 43a0ecd3398..5871b450652 100644 --- a/tests/ut/python/ops/test_ops_check.py +++ b/tests/ut/python/ops/test_ops_check.py @@ -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): diff --git a/tests/ut/python/pipeline/parse/test_grammar_constraints.py b/tests/ut/python/pipeline/parse/test_grammar_constraints.py index 19aa9b0a70d..568a0d4bcc7 100644 --- a/tests/ut/python/pipeline/parse/test_grammar_constraints.py +++ b/tests/ut/python/pipeline/parse/test_grammar_constraints.py @@ -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 diff --git a/tests/ut/python/pipeline/parse/test_super.py b/tests/ut/python/pipeline/parse/test_super.py index a8a1240cd1a..d68fa5cb1c3 100644 --- a/tests/ut/python/pipeline/parse/test_super.py +++ b/tests/ut/python/pipeline/parse/test_super.py @@ -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():