提交 3a738c40 编写于 作者: HansBug's avatar HansBug 😆

dev(hansbug): add base delayed option (not implemented)

上级 7078368f
......@@ -6,11 +6,13 @@ from libcpp cimport bool
from .modes cimport _e_tree_mode
cdef object _c_func_treelize_run(object func, list args, dict kwargs,
_e_tree_mode mode, bool inherit, bool allow_missing, object missing_func)
_e_tree_mode mode, bool inherit,
bool allow_missing, object missing_func,
bool delayed)
cpdef object _d_func_treelize(object func, object mode, object return_type, bool inherit, object missing,
object subside, object rise)
bool delayed, object subside, object rise)
cdef object _c_common_value(object item)
cdef tuple _c_missing_process(object missing)
cpdef object func_treelize(object mode= *, object return_type= *, bool inherit= *, object missing= *,
object subside= *, object rise= *)
bool delayed= *, object subside= *, object rise= *)
......@@ -17,7 +17,9 @@ _VALUE_IS_MISSING = SingletonMark('value_is_missing')
MISSING_NOT_ALLOW = SingletonMark("missing_not_allow")
cdef object _c_func_treelize_run(object func, list args, dict kwargs,
_e_tree_mode mode, bool inherit, bool allow_missing, object missing_func):
_e_tree_mode mode, bool inherit,
bool allow_missing, object missing_func,
bool delayed):
cdef list ck_args = []
cdef list ck_kwargs = []
cdef bool has_tree = False
......@@ -117,7 +119,7 @@ cdef object _c_func_treelize_run(object func, list args, dict kwargs,
))
_d_res[k] = _c_func_treelize_run(func, _l_args, _d_kwargs,
mode, inherit, allow_missing, missing_func)
mode, inherit, allow_missing, missing_func, delayed)
return TreeStorage(_d_res)
......@@ -131,7 +133,7 @@ def _w_rise_func(object tree, bool dict_=True, bool list_=True, bool tuple_=True
# runtime function
def _w_func_treelize_run(*args, object __w_func, _e_tree_mode __w_mode, object __w_return_type,
bool __w_inherit, bool __w_allow_missing, object __w_missing_func,
object __w_subside, object __w_rise, **kwargs):
bool __w_delayed, object __w_subside, object __w_rise, **kwargs):
cdef list _a_args = [(item._detach() if isinstance(item, TreeValue) else item) for item in args]
cdef dict _a_kwargs = {k: (v._detach() if isinstance(v, TreeValue) else v) for k, v in kwargs.items()}
......@@ -140,7 +142,7 @@ def _w_func_treelize_run(*args, object __w_func, _e_tree_mode __w_mode, object _
_a_kwargs = {key: _w_subside_func(value, **__w_subside) for key, value in _a_kwargs.items()}
cdef object _st_res = _c_func_treelize_run(__w_func, _a_args, _a_kwargs, __w_mode,
__w_inherit, __w_allow_missing, __w_missing_func)
__w_inherit, __w_allow_missing, __w_missing_func, __w_delayed)
cdef object _o_res
if __w_return_type is not None:
......@@ -176,7 +178,7 @@ cdef inline tuple _c_missing_process(object missing):
# build-time function
cpdef object _d_func_treelize(object func, object mode, object return_type, bool inherit, object missing,
object subside, object rise):
bool delayed, object subside, object rise):
cdef _e_tree_mode _v_mode = _c_load_mode(mode)
cdef bool allow_missing
cdef object missing_func
......@@ -195,12 +197,12 @@ cpdef object _d_func_treelize(object func, object mode, object return_type, bool
_c_check(_v_mode, return_type, inherit, allow_missing, missing_func)
return partial(_w_func_treelize_run, __w_func=func, __w_mode=_v_mode, __w_return_type=return_type,
__w_inherit=inherit, __w_allow_missing=allow_missing, __w_missing_func=missing_func,
__w_subside=_v_subside, __w_rise=_v_rise)
__w_delayed=delayed, __w_subside=_v_subside, __w_rise=_v_rise)
@cython.binding(True)
cpdef object func_treelize(object mode='strict', object return_type=TreeValue,
bool inherit=True, object missing=MISSING_NOT_ALLOW,
object subside=None, object rise=None):
bool delayed=False, object subside=None, object rise=None):
"""
Overview:
Wrap a common function to tree-supported function.
......@@ -233,4 +235,4 @@ cpdef object func_treelize(object mode='strict', object return_type=TreeValue,
>>> ssum(t1, t2) # TreeValue({'a': 12, 'b': 24, 'x': {'c': 36, 'd': 9}})
"""
return partial(_d_func_treelize, mode=mode, return_type=return_type,
inherit=inherit, missing=missing, subside=subside, rise=rise)
inherit=inherit, missing=missing, delayed=delayed, subside=subside, rise=rise)
......@@ -12,7 +12,7 @@ TreeClassType_ = TypeVar("TreeClassType_", bound=TreeValue)
def func_treelize(mode: str = 'strict', return_type: Optional[Type[TreeClassType_]] = TreeValue,
inherit: bool = True, missing: Union[Any, Callable] = MISSING_NOT_ALLOW,
inherit: bool = True, missing: Union[Any, Callable] = MISSING_NOT_ALLOW, delayed: bool = False,
subside: Union[Mapping, bool, None] = None, rise: Union[Mapping, bool, None] = None):
"""
Overview:
......@@ -21,7 +21,7 @@ def func_treelize(mode: str = 'strict', return_type: Optional[Type[TreeClassType
Arguments:
- mode (:obj:`str`): Mode of the wrapping, default is `strict`.
- return_type (:obj:`Optional[Type[TreeClassType_]]`): Return type of the wrapped function, default is `TreeValue`.
- inherit (:obj:`bool`): Allow inherit in wrapped function, default is `True`.
- inherit (:obj:`bool`): Allow inheriting in wrapped function, default is `True`.
- missing (:obj:`Union[Any, Callable]`): Missing value or lambda generator of when missing, \
default is `MISSING_NOT_ALLOW`, which means raise `KeyError` when missing detected.
- subside (:obj:`Union[Mapping, bool, None]`): Subside enabled to function's arguments or not, \
......@@ -47,7 +47,7 @@ def func_treelize(mode: str = 'strict', return_type: Optional[Type[TreeClassType
"""
def _decorator(func):
_treelized = _c_func_treelize(mode, return_type, inherit, missing, subside, rise)(func)
_treelized = _c_func_treelize(mode, return_type, inherit, missing, delayed, subside, rise)(func)
@wraps(func)
def _new_func(*args, **kwargs):
......@@ -82,7 +82,7 @@ def method_treelize(mode: str = 'strict', return_type: Optional[Type[TreeClassTy
- mode (:obj:`str`): Mode of the wrapping, default is `strict`.
- return_type (:obj:`Optional[Type[TreeClassType_]]`): Return type of the wrapped function, \
default is `AUTO_DETECT_RETURN_VALUE`, which means automatically use the decorated method's class.
- inherit (:obj:`bool`): Allow inherit in wrapped function, default is `True`.
- inherit (:obj:`bool`): Allow inheriting in wrapped function, default is `True`.
- missing (:obj:`Union[Any, Callable]`): Missing value or lambda generator of when missing, \
default is `MISSING_NOT_ALLOW`, which means raise `KeyError` when missing detected.
- subside (:obj:`Union[Mapping, bool, None]`): Subside enabled to function's arguments or not, \
......@@ -154,7 +154,7 @@ def classmethod_treelize(mode: str = 'strict', return_type: Optional[Type[TreeCl
- mode (:obj:`str`): Mode of the wrapping, default is `strict`.
- return_type (:obj:`Optional[Type[TreeClassType_]]`): Return type of the wrapped function, \
default is `AUTO_DETECT_RETURN_VALUE`, which means automatically use the decorated method's class.
- inherit (:obj:`bool`): Allow inherit in wrapped function, default is `True`.
- inherit (:obj:`bool`): Allow inheriting in wrapped function, default is `True`.
- missing (:obj:`Union[Any, Callable]`): Missing value or lambda generator of when missing, \
default is `MISSING_NOT_ALLOW`, which means raise `KeyError` when missing detected.
- subside (:obj:`Union[Mapping, bool, None]`): Subside enabled to function's arguments or not, \
......
......@@ -94,7 +94,7 @@ cdef object _c_subside(object value, bool dict_, bool list_, bool tuple_, bool i
allow_missing, missing_func = _c_missing_process(missing)
return _c_func_treelize_run(_SubsideCall(builder), args, {},
_c_load_mode(mode), inherit, allow_missing, missing_func), _i_types
_c_load_mode(mode), inherit, allow_missing, missing_func, False), _i_types
cdef inline object _c_subside_keep_type(object t):
return t
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册