private-attribute-cpp 2.1.15__tar.gz → 2.1.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {private_attribute_cpp-2.1.15/private_attribute_cpp.egg-info → private_attribute_cpp-2.1.17}/PKG-INFO +1 -1
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/private_attribute.cpp +39 -15
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/private_attribute.pyi +6 -5
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17/private_attribute_cpp.egg-info}/PKG-INFO +1 -1
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/setup.py +1 -1
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/LICENSE +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/MANIFEST.in +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/README.md +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/picosha2.h +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/private_attribute_cpp.egg-info/SOURCES.txt +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/private_attribute_cpp.egg-info/dependency_links.txt +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/private_attribute_cpp.egg-info/not-zip-safe +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/private_attribute_cpp.egg-info/top_level.txt +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/setup.cfg +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_attr_classify_owner.py +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_class_private_attrs.py +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_gc_collect.py +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_private_abc.py +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_private_attrs.py +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_private_func.py +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_private_inheritance.py +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_private_method.py +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_private_wrap.py +0 -0
- {private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_slots_cycle.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: private_attribute_cpp
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.17
|
|
4
4
|
Summary: A Python package that provides a way to define private attributes in C++ implementation.
|
|
5
5
|
Home-page: https://github.com/Locked-chess-official/private_attribute_cpp
|
|
6
6
|
Author: HuangHaoHua
|
|
@@ -3188,9 +3188,14 @@ new_type_tp_setattro(PyObject* self, PyObject* name, PyObject* value) noexcept
|
|
|
3188
3188
|
return result;
|
|
3189
3189
|
}
|
|
3190
3190
|
|
|
3191
|
+
static bool has_init_slots = false;
|
|
3192
|
+
|
|
3191
3193
|
static int
|
|
3192
3194
|
init_all_slots() noexcept
|
|
3193
3195
|
{
|
|
3196
|
+
if (has_init_slots || PyType_Type.tp_setattro == new_type_tp_setattro) {
|
|
3197
|
+
return 0;
|
|
3198
|
+
}
|
|
3194
3199
|
original_type_tp_setattro = PyType_Type.tp_setattro;
|
|
3195
3200
|
PyObject* original_setattr = PyObject_GetAttrString((PyObject*)&PyType_Type, "__setattr__");
|
|
3196
3201
|
if (!original_setattr) {return -1;}
|
|
@@ -3209,6 +3214,7 @@ init_all_slots() noexcept
|
|
|
3209
3214
|
if (!all_metaclasses) {return -1;}
|
|
3210
3215
|
if (!PyList_Check(all_metaclasses)) {
|
|
3211
3216
|
Py_DECREF(all_metaclasses);
|
|
3217
|
+
has_init_slots = true;
|
|
3212
3218
|
return 0;
|
|
3213
3219
|
}
|
|
3214
3220
|
Py_ssize_t list_len = PyList_GET_SIZE(all_metaclasses);
|
|
@@ -3220,6 +3226,7 @@ init_all_slots() noexcept
|
|
|
3220
3226
|
}
|
|
3221
3227
|
}
|
|
3222
3228
|
Py_DECREF(all_metaclasses);
|
|
3229
|
+
has_init_slots = true;
|
|
3223
3230
|
return 0;
|
|
3224
3231
|
}
|
|
3225
3232
|
|
|
@@ -3675,6 +3682,29 @@ PrivateTempObject_dealloc(PyObject* self) noexcept
|
|
|
3675
3682
|
Py_TYPE(self)->tp_free(self);
|
|
3676
3683
|
}
|
|
3677
3684
|
|
|
3685
|
+
static PyObject*
|
|
3686
|
+
PrivateTempObject_postprocess(PyObject* self, PyObject* type) noexcept
|
|
3687
|
+
{
|
|
3688
|
+
if (!PyType_Check(type)) {
|
|
3689
|
+
PyErr_SetString(PyExc_TypeError, "type must be a type");
|
|
3690
|
+
return NULL;
|
|
3691
|
+
}
|
|
3692
|
+
if ((((PrivateTempObject*)self)->tmp->cleared)) {
|
|
3693
|
+
PyErr_SetString(PyExc_RuntimeError, "temp not init or have been used");
|
|
3694
|
+
return NULL;
|
|
3695
|
+
}
|
|
3696
|
+
if (!PrivateAttrType_postprocess(type, *(((PrivateTempObject*)self)->tmp))) {
|
|
3697
|
+
return NULL;
|
|
3698
|
+
}
|
|
3699
|
+
((PrivateTempObject*)self)->tmp->clear();
|
|
3700
|
+
Py_RETURN_NONE;
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
static PyMethodDef PrivateTempObject_methods[] = {
|
|
3704
|
+
{"postprocess", (PyCFunction)PrivateTempObject_postprocess, METH_O, "postprocess the temp object"},
|
|
3705
|
+
{NULL}
|
|
3706
|
+
};
|
|
3707
|
+
|
|
3678
3708
|
static PyTypeObject PrivateTempType = {
|
|
3679
3709
|
PyVarObject_HEAD_INIT(NULL, 0)
|
|
3680
3710
|
"private_attribute._PrivateTemp", // tp_name
|
|
@@ -3703,7 +3733,7 @@ static PyTypeObject PrivateTempType = {
|
|
|
3703
3733
|
0, //tp_weaklistoffset
|
|
3704
3734
|
0, //tp_iter
|
|
3705
3735
|
0, //tp_iternext
|
|
3706
|
-
|
|
3736
|
+
PrivateTempObject_methods, //tp_methods
|
|
3707
3737
|
0, //tp_members
|
|
3708
3738
|
PrivateTempObject_getsets //tp_getset
|
|
3709
3739
|
};
|
|
@@ -3735,19 +3765,7 @@ postprocess_for_PrivateAttr(PyObject* /*self*/, PyObject* args) noexcept
|
|
|
3735
3765
|
if (!PyArg_ParseTuple(args, "OO", &type, &tmp)) {
|
|
3736
3766
|
return NULL;
|
|
3737
3767
|
}
|
|
3738
|
-
|
|
3739
|
-
PyErr_SetString(PyExc_TypeError, "type must be a type");
|
|
3740
|
-
return NULL;
|
|
3741
|
-
}
|
|
3742
|
-
if (!PyObject_TypeCheck(tmp, &PrivateTempType)) {
|
|
3743
|
-
PyErr_SetString(PyExc_TypeError, "tmp must be a private_temp");
|
|
3744
|
-
return NULL;
|
|
3745
|
-
}
|
|
3746
|
-
if (!PrivateAttrType_postprocess(type, *(((PrivateTempObject*)tmp)->tmp))) {
|
|
3747
|
-
return NULL;
|
|
3748
|
-
}
|
|
3749
|
-
((PrivateTempObject*)tmp)->tmp->clear();
|
|
3750
|
-
Py_RETURN_NONE;
|
|
3768
|
+
return PrivateTempObject_postprocess(tmp, type);
|
|
3751
3769
|
}
|
|
3752
3770
|
|
|
3753
3771
|
#define METACLASS_WEAKREF_CALLBACK_REMOVE_ITEM(name) do {\
|
|
@@ -4115,7 +4133,7 @@ class PrivateAbcMeta(ABCMeta):
|
|
|
4115
4133
|
def __new__(cls, *args, **kwargs):
|
|
4116
4134
|
temp = private_attribute.prepare(*args, **kwargs)
|
|
4117
4135
|
typ = super().__new__(cls, temp.name, temp.bases, temp.attrs, **temp.kwds)
|
|
4118
|
-
private_attribute.postprocess(typ, temp)
|
|
4136
|
+
private_attribute.postprocess(typ, temp) # or temp.postprocess(typ)
|
|
4119
4137
|
return typ
|
|
4120
4138
|
|
|
4121
4139
|
private_attribute.register_metaclass(PrivateAbcMeta)
|
|
@@ -4301,9 +4319,14 @@ static PyMethodDef clean_storage = {
|
|
|
4301
4319
|
"Clean all storages"
|
|
4302
4320
|
};
|
|
4303
4321
|
|
|
4322
|
+
static bool resigtered_clean_func = false;
|
|
4323
|
+
|
|
4304
4324
|
static int
|
|
4305
4325
|
atexit_register_clean_func(void) noexcept
|
|
4306
4326
|
{
|
|
4327
|
+
if (resigtered_clean_func) {
|
|
4328
|
+
return 0;
|
|
4329
|
+
}
|
|
4307
4330
|
PyObject* atexit = PyImport_ImportModule("atexit");
|
|
4308
4331
|
if (!atexit) {
|
|
4309
4332
|
return -1;
|
|
@@ -4323,6 +4346,7 @@ atexit_register_clean_func(void) noexcept
|
|
|
4323
4346
|
return -1;
|
|
4324
4347
|
}
|
|
4325
4348
|
Py_DECREF(result);
|
|
4349
|
+
resigtered_clean_func = true;
|
|
4326
4350
|
return 0;
|
|
4327
4351
|
}
|
|
4328
4352
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""A module that provides a metaclass for creating classes with private attributes.
|
|
2
|
-
Private attributes are defined in the `__private_attrs__` sequence and are only
|
|
3
|
-
You can use the `PrivateAttrBase`
|
|
2
|
+
Private attributes are defined in the `__private_attrs__` sequence and are only visitable in class codes.
|
|
3
|
+
You can use the `PrivateAttrBase` as the base class to create classes with private attributes.
|
|
4
4
|
The attributes which are private are not on the instance's `__dict__` and cannot be accessed outside
|
|
5
5
|
but in the methods defined in class it is reachable.
|
|
6
6
|
Usage example:
|
|
@@ -105,6 +105,7 @@ class _PrivateTemp:
|
|
|
105
105
|
def attrs(self) -> dict[str, Any]: ...
|
|
106
106
|
@property
|
|
107
107
|
def kwds(self) -> dict[str, Any]: ...
|
|
108
|
+
def postprocess(self, typ: type, /) -> None: ... # add in 2.1.17
|
|
108
109
|
|
|
109
110
|
def prepare(name: str, bases: tuple, attrs: _PrivateAttrDict, /, **kwds) -> _PrivateTemp:
|
|
110
111
|
"""
|
|
@@ -129,7 +130,7 @@ def prepare(name: str, bases: tuple, attrs: _PrivateAttrDict, /, **kwds) -> _Pri
|
|
|
129
130
|
def __new__(cls, *args, **kwargs):
|
|
130
131
|
temp = private_attribute.prepare(*args, **kwargs)
|
|
131
132
|
typ = super().__new__(cls, temp.name, temp.bases, temp.attrs, **temp.kwds)
|
|
132
|
-
private_attribute.postprocess(typ, temp)
|
|
133
|
+
private_attribute.postprocess(typ, temp) # or temp.postprocess(typ)
|
|
133
134
|
return typ
|
|
134
135
|
|
|
135
136
|
private_attribute.register_metaclass(PrivateAbcMeta)
|
|
@@ -160,7 +161,7 @@ def postprocess(typ: type, temp: _PrivateTemp, /) -> None:
|
|
|
160
161
|
def __new__(cls, *args, **kwargs):
|
|
161
162
|
temp = private_attribute.prepare(*args, **kwargs)
|
|
162
163
|
typ = super().__new__(cls, temp.name, temp.bases, temp.attrs, **temp.kwds)
|
|
163
|
-
private_attribute.postprocess(typ, temp)
|
|
164
|
+
private_attribute.postprocess(typ, temp) # or temp.postprocess(typ)
|
|
164
165
|
return typ
|
|
165
166
|
|
|
166
167
|
private_attribute.register_metaclass(PrivateAbcMeta)
|
|
@@ -190,7 +191,7 @@ def register_metaclass(typ: type, /) -> None:
|
|
|
190
191
|
def __new__(cls, *args, **kwargs):
|
|
191
192
|
temp = private_attribute.prepare(*args, **kwargs)
|
|
192
193
|
typ = super().__new__(cls, temp.name, temp.bases, temp.attrs, **temp.kwds)
|
|
193
|
-
private_attribute.postprocess(typ, temp)
|
|
194
|
+
private_attribute.postprocess(typ, temp) # or temp.postprocess(typ)
|
|
194
195
|
return typ
|
|
195
196
|
|
|
196
197
|
private_attribute.register_metaclass(PrivateAbcMeta)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: private_attribute_cpp
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.17
|
|
4
4
|
Summary: A Python package that provides a way to define private attributes in C++ implementation.
|
|
5
5
|
Home-page: https://github.com/Locked-chess-official/private_attribute_cpp
|
|
6
6
|
Author: HuangHaoHua
|
|
@@ -24,7 +24,7 @@ readme = open('README.md').read()
|
|
|
24
24
|
|
|
25
25
|
setup(
|
|
26
26
|
name='private_attribute_cpp',
|
|
27
|
-
version='2.1.
|
|
27
|
+
version='2.1.17',
|
|
28
28
|
author="HuangHaoHua",
|
|
29
29
|
author_email="13140752715@example.com",
|
|
30
30
|
description='A Python package that provides a way to define private attributes in C++ implementation.',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_attr_classify_owner.py
RENAMED
|
File without changes
|
{private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_class_private_attrs.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{private_attribute_cpp-2.1.15 → private_attribute_cpp-2.1.17}/tests/test_private_inheritance.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|