Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDILab开源决策智能平台
treevalue
提交
c7520b1d
T
treevalue
项目概览
OpenDILab开源决策智能平台
/
treevalue
大约 1 年 前同步成功
通知
3
Star
213
Fork
3
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
treevalue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c7520b1d
编写于
7月 19, 2021
作者:
HansBug
😆
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add new part
上级
03d84373
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
63 addition
and
0 deletion
+63
-0
treevalue/tree/__init__.py
treevalue/tree/__init__.py
+2
-0
treevalue/tree/common/tree.py
treevalue/tree/common/tree.py
+2
-0
treevalue/tree/tree/__init__.py
treevalue/tree/tree/__init__.py
+1
-0
treevalue/tree/tree/tree.py
treevalue/tree/tree/tree.py
+53
-0
treevalue/tree/tree/utils.py
treevalue/tree/tree/utils.py
+5
-0
未找到文件。
treevalue/tree/__init__.py
浏览文件 @
c7520b1d
from
.common
import
*
from
.tree
import
*
treevalue/tree/common/tree.py
浏览文件 @
c7520b1d
from
functools
import
wraps
from
typing
import
Dict
,
Any
,
Union
,
List
from
typing
import
Dict
,
Any
,
Union
,
List
from
.base
import
BaseTree
from
.base
import
BaseTree
...
@@ -5,6 +6,7 @@ from ...utils import init_magic
...
@@ -5,6 +6,7 @@ from ...utils import init_magic
def
_to_tree_decorator
(
init_func
):
def
_to_tree_decorator
(
init_func
):
@
wraps
(
init_func
)
def
_new_init_func
(
data
):
def
_new_init_func
(
data
):
if
isinstance
(
data
,
Tree
):
if
isinstance
(
data
,
Tree
):
_new_init_func
(
data
.
to_json
())
_new_init_func
(
data
.
to_json
())
...
...
treevalue/tree/tree/__init__.py
0 → 100644
浏览文件 @
c7520b1d
from
.tree
import
TreeValue
treevalue/tree/tree/tree.py
0 → 100644
浏览文件 @
c7520b1d
from
functools
import
wraps
from
..common
import
BaseTree
,
Tree
from
...utils
import
init_magic
_DATA_PROPERTY
=
'_property__data'
_PRESERVED_PROPERTIES
=
{
_DATA_PROPERTY
,
}
def
_get_data_property
(
t
:
'TreeValue'
)
->
BaseTree
:
return
getattr
(
t
,
_DATA_PROPERTY
)
def
_init_decorate
(
init_func
):
@
wraps
(
init_func
)
def
_new_init_func
(
data
):
if
isinstance
(
data
,
TreeValue
):
_new_init_func
(
_get_data_property
(
data
))
elif
isinstance
(
data
,
dict
):
_new_init_func
(
Tree
(
data
))
elif
isinstance
(
data
,
Tree
):
init_func
(
data
)
else
:
raise
TypeError
(
"Unknown initialization type for tree value - {type}."
.
format
(
type
=
repr
(
type
(
data
).
__name__
)))
return
_new_init_func
@
init_magic
(
_init_decorate
)
class
TreeValue
:
def
__init__
(
self
,
data
:
BaseTree
):
setattr
(
self
,
_DATA_PROPERTY
,
data
)
def
__getattr__
(
self
,
key
):
if
key
in
_PRESERVED_PROPERTIES
:
return
object
.
__getattribute__
(
key
)
else
:
return
_get_data_property
(
self
).
__getitem__
(
key
)
def
__setattr__
(
self
,
key
,
value
):
if
key
in
_PRESERVED_PROPERTIES
:
object
.
__setattr__
(
self
,
key
,
value
)
else
:
return
_get_data_property
(
self
).
__setattr__
(
key
,
value
)
def
__delattr__
(
self
,
key
):
if
key
in
_PRESERVED_PROPERTIES
:
object
.
__delattr__
(
self
,
key
)
else
:
return
_get_data_property
(
self
).
__delattr__
(
key
)
treevalue/tree/tree/utils.py
0 → 100644
浏览文件 @
c7520b1d
from
.tree
import
TreeValue
,
_get_data_property
def
to_json
(
tree
:
TreeValue
):
return
_get_data_property
(
tree
).
to_json
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录