Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
f362503d
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f362503d
编写于
7月 18, 2020
作者:
W
Wei Luning
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support throw attribute error from c++
上级
c5eae497
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
61 addition
and
4 deletion
+61
-4
mindspore/ccsrc/pipeline/jit/pipeline.cc
mindspore/ccsrc/pipeline/jit/pipeline.cc
+4
-0
mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc
mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc
+2
-2
mindspore/ccsrc/pybind_api/pybind_patch.h
mindspore/ccsrc/pybind_api/pybind_patch.h
+24
-0
mindspore/ccsrc/utils/log_adapter.cc
mindspore/ccsrc/utils/log_adapter.cc
+3
-2
mindspore/ccsrc/utils/log_adapter.h
mindspore/ccsrc/utils/log_adapter.h
+1
-0
mindspore/ccsrc/utils/log_adapter_py.cc
mindspore/ccsrc/utils/log_adapter_py.cc
+4
-0
tests/ut/python/pynative_mode/test_parse_method.py
tests/ut/python/pynative_mode/test_parse_method.py
+23
-0
未找到文件。
mindspore/ccsrc/pipeline/jit/pipeline.cc
浏览文件 @
f362503d
...
...
@@ -40,6 +40,7 @@
#include "debug/trace.h"
#include "pipeline/pynative/pynative_execute.h"
#include "frontend/optimizer/py_pass_manager.h"
#include "pybind_api/pybind_patch.h"
#if (!_WIN32 && !ENABLE_GE && !ENABLE_TESTCASES)
#include "frontend/parallel/ps/common.h"
...
...
@@ -536,6 +537,9 @@ bool ExecutorPy::Compile(const py::object &obj, const py::tuple &args, const py:
}
catch
(
const
py
::
index_error
&
ex
)
{
ReleaseResource
(
phase
);
throw
py
::
index_error
(
ex
);
}
catch
(
const
py
::
attribute_error
&
ex
)
{
ReleaseResource
(
phase
);
throw
py
::
attribute_error
(
ex
);
}
catch
(
const
std
::
exception
&
ex
)
{
ReleaseResource
(
phase
);
// re-throw this exception to Python interpreter to handle it
...
...
mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc
浏览文件 @
f362503d
...
...
@@ -761,8 +761,8 @@ EvalResultPtr GetEvaluatedValueForClassAttrOrMethod(const AnalysisEnginePtr &eng
ValuePtr
method
=
cls
->
GetMethod
(
item_name
);
if
(
method
->
isa
<
AnyValue
>
())
{
MS_
LOG
(
EXCEPTION
)
<<
"Unknown field, data type: "
<<
args_spec_list
[
0
]
->
BuildType
()
->
ToString
()
<<
", item value: "
<<
item_v
->
ToString
();
MS_
EXCEPTION
(
AttributeError
)
<<
"Unknown field, data type: "
<<
args_spec_list
[
0
]
->
BuildType
()
->
ToString
()
<<
", item value: "
<<
item_v
->
ToString
();
}
// Infer class method
...
...
mindspore/ccsrc/pybind_api/pybind_patch.h
0 → 100644
浏览文件 @
f362503d
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PYBIND_API_PYBIND_PATCH_H_
#define PYBIND_API_PYBIND_PATCH_H_
namespace
pybind11
{
PYBIND11_RUNTIME_EXCEPTION
(
attribute_error
,
PyExc_AttributeError
)
}
#endif // PYBIND_API_PYBIND_PATCH_H_
mindspore/ccsrc/utils/log_adapter.cc
浏览文件 @
f362503d
...
...
@@ -145,10 +145,11 @@ static std::string ExceptionTypeToString(ExceptionType type) {
_TO_STRING
(
IndexError
),
_TO_STRING
(
ValueError
),
_TO_STRING
(
TypeError
),
_TO_STRING
(
AttributeError
),
};
// clang-format on
#undef _TO_STRING
if
(
type
<
UnknownError
||
type
>
Typ
eError
)
{
if
(
type
<
UnknownError
||
type
>
Attribut
eError
)
{
type
=
UnknownError
;
}
return
std
::
string
(
type_names
[
type
]);
...
...
@@ -212,7 +213,7 @@ void LogWriter::operator^(const LogStream &stream) const {
std
::
ostringstream
oss
;
oss
<<
location_
.
file_
<<
":"
<<
location_
.
line_
<<
" "
<<
location_
.
func_
<<
"] "
;
if
(
exception_type_
!=
NoExceptionType
&&
exception_type_
!=
IndexError
&&
exception_type_
!=
TypeError
&&
exception_type_
!=
ValueError
)
{
exception_type_
!=
ValueError
&&
exception_type_
!=
AttributeError
)
{
oss
<<
ExceptionTypeToString
(
exception_type_
)
<<
" "
;
}
oss
<<
msg
.
str
();
...
...
mindspore/ccsrc/utils/log_adapter.h
浏览文件 @
f362503d
...
...
@@ -58,6 +58,7 @@ enum ExceptionType {
IndexError
,
ValueError
,
TypeError
,
AttributeError
,
};
struct
LocationInfo
{
...
...
mindspore/ccsrc/utils/log_adapter_py.cc
浏览文件 @
f362503d
...
...
@@ -18,6 +18,7 @@
#include <string>
#include "pybind11/pybind11.h"
#include "pybind_api/pybind_patch.h"
namespace
py
=
pybind11
;
namespace
mindspore
{
...
...
@@ -38,6 +39,9 @@ class PyExceptionInitializer {
if
(
exception_type
==
TypeError
)
{
throw
py
::
type_error
(
str
);
}
if
(
exception_type
==
AttributeError
)
{
throw
py
::
attribute_error
(
str
);
}
py
::
pybind11_fail
(
str
);
}
};
...
...
tests/ut/python/pynative_mode/test_parse_method.py
浏览文件 @
f362503d
...
...
@@ -304,6 +304,29 @@ def test_access():
""" test_access """
invoke_dataclass
(
1
,
2
)
@
dataclass
class
Access2
:
a
:
int
b
:
int
def
max
(
self
):
if
self
.
a
>
self
.
b
:
return
self
.
c
return
self
.
b
@
ms_function
def
invoke_dataclass2
(
x
,
y
):
""" invoke_dataclass """
acs
=
Access2
(
x
,
y
)
return
acs
.
max
()
def
test_access_attr_error
():
""" test_access """
with
pytest
.
raises
(
AttributeError
):
invoke_dataclass2
(
1
,
2
)
def
myfunc
(
x
):
""" myfunc """
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录