提交 3748f19a 编写于 作者: HansBug's avatar HansBug 😆

dev(hansbug): put constraint into it

上级 db5c6bc7
......@@ -3,6 +3,7 @@
from libcpp cimport bool
from .constraint cimport Constraint
from ..common.delay cimport DelayedProxy
from ..common.storage cimport TreeStorage
......@@ -11,6 +12,7 @@ cdef class _CObject:
cdef class TreeValue:
cdef readonly TreeStorage _st
cdef readonly Constraint _constraint
cdef readonly type _type
cpdef TreeStorage _detach(self)
......@@ -20,7 +22,7 @@ cdef class TreeValue:
cpdef _getitem_extern(self, object key)
cpdef _setitem_extern(self, object key, object value)
cpdef _delitem_extern(self, object key)
cdef void _update(self, object d, dict kwargs) except *
cdef void _update(self, object d, dict kwargs) except*
cpdef public get(self, str key, object default= *)
cpdef public pop(self, str key, object default= *)
cpdef public popitem(self)
......
......@@ -8,6 +8,7 @@ from operator import itemgetter
import cython
from hbutils.design import SingletonMark
from .constraint cimport Constraint, to_constraint, EmptyConstraint
from ..common.delay cimport undelay, _c_delayed_partial, DelayedProxy
from ..common.storage cimport TreeStorage, create_storage, _c_undelay_data
from ...utils import format_tree
......@@ -56,12 +57,13 @@ cdef class TreeValue:
The `TreeValue` class is a light-weight framework just for DIY.
"""
def __cinit__(self, object data):
def __cinit__(self, object data, Constraint constraint=None):
self._st = _DEFAULT_STORAGE
self._constraint = EmptyConstraint() if constraint is None else constraint
self._type = type(self)
@cython.binding(True)
def __init__(self, object data):
def __init__(self, object data, object constraint=None):
"""
Constructor of :class:`TreeValue`.
......@@ -100,6 +102,8 @@ cdef class TreeValue:
"Unknown initialization type for tree value - {type}.".format(
type=repr(type(data).__name__)))
self._constraint = to_constraint(constraint)
def __getnewargs_ex__(self): # for __cinit__, when pickle.loads
return ({},), {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册