private-attribute-cpp 1.4.2__tar.gz → 1.4.4__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-1.4.2/private_attribute_cpp.egg-info → private_attribute_cpp-1.4.4}/PKG-INFO +1 -1
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/private_attribute.cpp +53 -6
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/private_attribute.pyi +9 -9
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4/private_attribute_cpp.egg-info}/PKG-INFO +1 -1
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/setup.py +1 -1
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/LICENSE +0 -0
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/MANIFEST.in +0 -0
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/README.md +0 -0
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/picosha2.h +0 -0
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/private_attribute_cpp.egg-info/SOURCES.txt +0 -0
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/private_attribute_cpp.egg-info/dependency_links.txt +0 -0
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/private_attribute_cpp.egg-info/not-zip-safe +0 -0
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/private_attribute_cpp.egg-info/top_level.txt +0 -0
- {private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4}/setup.cfg +0 -0
{private_attribute_cpp-1.4.2/private_attribute_cpp.egg-info → private_attribute_cpp-1.4.4}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: private_attribute_cpp
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.4
|
|
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
|
|
@@ -138,8 +138,6 @@ namespace {
|
|
|
138
138
|
static std::unordered_map<uintptr_t, destructor> all_type_finalize;
|
|
139
139
|
|
|
140
140
|
static std::shared_mutex all_register_new_metaclass_mutex;
|
|
141
|
-
static std::vector<PyTypeObject*> all_register_new_metaclass;
|
|
142
|
-
static std::unordered_set<uintptr_t> all_register_new_metaclass_id;
|
|
143
141
|
static std::unordered_map<uintptr_t, PyObject*> all_register_type_weak_ref;
|
|
144
142
|
};
|
|
145
143
|
};
|
|
@@ -233,7 +231,7 @@ generate_private_attr_name(uintptr_t obj_id, const std::string& attr_name)
|
|
|
233
231
|
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ";
|
|
234
232
|
|
|
235
233
|
std::uniform_int_distribution<long long> dist(0, printable_chars.size() - 1);
|
|
236
|
-
|
|
234
|
+
|
|
237
235
|
auto generate_random_ascii = [&](int length) {
|
|
238
236
|
std::string result;
|
|
239
237
|
for(int i = 0; i < length; i++) {
|
|
@@ -1754,6 +1752,18 @@ struct PrivateAttrCreationData
|
|
|
1754
1752
|
if (cleared) {
|
|
1755
1753
|
return;
|
|
1756
1754
|
}
|
|
1755
|
+
if (name) {
|
|
1756
|
+
Py_DECREF(name);
|
|
1757
|
+
name = nullptr;
|
|
1758
|
+
}
|
|
1759
|
+
if (bases) {
|
|
1760
|
+
Py_DECREF(bases);
|
|
1761
|
+
bases = nullptr;
|
|
1762
|
+
}
|
|
1763
|
+
if (attrs) {
|
|
1764
|
+
Py_DECREF(attrs);
|
|
1765
|
+
attrs = nullptr;
|
|
1766
|
+
}
|
|
1757
1767
|
if (attrs_copy) {
|
|
1758
1768
|
Py_DECREF(attrs_copy);
|
|
1759
1769
|
attrs_copy = nullptr;
|
|
@@ -1987,6 +1997,9 @@ PrivateAttrType_preprocess(PyObject* args, PyObject* kwds, PrivateAttrCreationDa
|
|
|
1987
1997
|
if (!PyArg_ParseTuple(args, "OOO", &data.name, &data.bases, &data.attrs)) {
|
|
1988
1998
|
return false;
|
|
1989
1999
|
}
|
|
2000
|
+
Py_INCREF(data.name);
|
|
2001
|
+
Py_INCREF(data.bases);
|
|
2002
|
+
Py_INCREF(data.attrs);
|
|
1990
2003
|
|
|
1991
2004
|
if (!PyUnicode_Check(data.name)) {
|
|
1992
2005
|
PyErr_SetString(PyExc_TypeError, "name must be a string");
|
|
@@ -2315,6 +2328,10 @@ PrivateAttrType_postprocess(PyObject* new_type, PrivateAttrCreationData& data)
|
|
|
2315
2328
|
if (!new_type) {
|
|
2316
2329
|
return false;
|
|
2317
2330
|
}
|
|
2331
|
+
if (!PyType_Check(new_type)) {
|
|
2332
|
+
PyErr_SetString(PyExc_TypeError, "created object is not a type");
|
|
2333
|
+
return false;
|
|
2334
|
+
}
|
|
2318
2335
|
|
|
2319
2336
|
PyTypeObject* type_instance = (PyTypeObject*)new_type;
|
|
2320
2337
|
uintptr_t type_id = (uintptr_t)(type_instance);
|
|
@@ -2423,7 +2440,13 @@ PrivateAttrType_postprocess(PyObject* new_type, PrivateAttrCreationData& data)
|
|
|
2423
2440
|
analyse_all_code(original_value, ::AllData::type_allowed_code_map[type_id], set);
|
|
2424
2441
|
}
|
|
2425
2442
|
}
|
|
2426
|
-
|
|
2443
|
+
|
|
2444
|
+
// Python >= 3.13, delete the attr "__static_attributes__"
|
|
2445
|
+
#if PY_VERSION_HEX >= 0x030D0000
|
|
2446
|
+
PyDict_DelItemString(type_instance->tp_dict, "__static_attributes__");
|
|
2447
|
+
PyErr_Clear();
|
|
2448
|
+
#endif
|
|
2449
|
+
|
|
2427
2450
|
return true;
|
|
2428
2451
|
}
|
|
2429
2452
|
|
|
@@ -3189,7 +3212,7 @@ static PyMethodDef PrivateModule_methods[] = {
|
|
|
3189
3212
|
static PyTypeObject PrivateModuleType = {
|
|
3190
3213
|
PyVarObject_HEAD_INIT(NULL, 0)
|
|
3191
3214
|
"private_attribute_module", //tp_name
|
|
3192
|
-
PyModule_Type.tp_basicsize + 8, //tp_basicsize size of module object + 8 bytes for
|
|
3215
|
+
PyModule_Type.tp_basicsize + 8, //tp_basicsize size of module object + 8 bytes for basicsize to avoid changing attribute '__class__'
|
|
3193
3216
|
0, //tp_itemsize
|
|
3194
3217
|
0, //tp_dealloc
|
|
3195
3218
|
0, //tp_print
|
|
@@ -3262,14 +3285,38 @@ PyInit_private_attribute(void)
|
|
|
3262
3285
|
PyType_Ready(&PrivateTempType) < 0) {
|
|
3263
3286
|
return NULL;
|
|
3264
3287
|
}
|
|
3265
|
-
|
|
3288
|
+
PyObject* all = PyList_New(0);
|
|
3289
|
+
if (!all) {
|
|
3290
|
+
return NULL;
|
|
3291
|
+
}
|
|
3266
3292
|
PyObject* m = PyModule_Create(&def);
|
|
3267
3293
|
if (!m) {
|
|
3294
|
+
Py_DECREF(all);
|
|
3268
3295
|
return NULL;
|
|
3269
3296
|
}
|
|
3270
3297
|
#ifdef Py_GIL_DISABLED
|
|
3271
3298
|
PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED);
|
|
3272
3299
|
#endif
|
|
3300
|
+
|
|
3301
|
+
PyModule_AddObject(m, "__all__", all);
|
|
3302
|
+
/* all contains:
|
|
3303
|
+
* PrivateWrapProxy
|
|
3304
|
+
* PrivateAttrType
|
|
3305
|
+
* PrivateAttrBase
|
|
3306
|
+
* prepare
|
|
3307
|
+
* postprocess
|
|
3308
|
+
* register_metaclass
|
|
3309
|
+
* ensure_type
|
|
3310
|
+
* ensure_metaclass
|
|
3311
|
+
*/
|
|
3312
|
+
PyList_Append(all, PyUnicode_FromString("PrivateWrapProxy"));
|
|
3313
|
+
PyList_Append(all, PyUnicode_FromString("PrivateAttrType"));
|
|
3314
|
+
PyList_Append(all, PyUnicode_FromString("PrivateAttrBase"));
|
|
3315
|
+
PyList_Append(all, PyUnicode_FromString("prepare"));
|
|
3316
|
+
PyList_Append(all, PyUnicode_FromString("postprocess"));
|
|
3317
|
+
PyList_Append(all, PyUnicode_FromString("register_metaclass"));
|
|
3318
|
+
PyList_Append(all, PyUnicode_FromString("ensure_type"));
|
|
3319
|
+
PyList_Append(all, PyUnicode_FromString("ensure_metaclass"));
|
|
3273
3320
|
Py_SET_TYPE(m, &PrivateModuleType);
|
|
3274
3321
|
return m;
|
|
3275
3322
|
}
|
|
@@ -19,14 +19,14 @@ from typing import Any, TypeVar, Callable, TypedDict, Sequence, Generic
|
|
|
19
19
|
from types import FunctionType
|
|
20
20
|
|
|
21
21
|
# define the dict that must have a key "__private_attrs__" and value must be the sequence of strings
|
|
22
|
-
class
|
|
22
|
+
class _PrivateAttrDict(TypedDict):
|
|
23
23
|
__private_attrs__: Sequence[str]
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
_T = TypeVar('T')
|
|
26
26
|
|
|
27
|
-
class _PrivateWrap(Generic[
|
|
27
|
+
class _PrivateWrap(Generic[_T]):
|
|
28
28
|
@property
|
|
29
|
-
def result(self) ->
|
|
29
|
+
def result(self) -> _T:
|
|
30
30
|
"the final result of decorating"
|
|
31
31
|
...
|
|
32
32
|
|
|
@@ -38,7 +38,7 @@ class _PrivateWrap(Generic[T]):
|
|
|
38
38
|
def __getattr__(self, name: str) -> Any:
|
|
39
39
|
return getattr(self.result, name)
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
_TVar = TypeVar('TVar')
|
|
42
42
|
|
|
43
43
|
class PrivateWrapProxy:
|
|
44
44
|
"""
|
|
@@ -70,13 +70,13 @@ class PrivateWrapProxy:
|
|
|
70
70
|
def my_method(self): ...
|
|
71
71
|
```
|
|
72
72
|
"""
|
|
73
|
-
def __init__(self, decorator: Callable[[
|
|
74
|
-
def __call__(self, func:
|
|
73
|
+
def __init__(self, decorator: Callable[[_TVar], _T], orig: _PrivateWrap[Any]|None = None, /) -> None: ...
|
|
74
|
+
def __call__(self, func: _TVar, /) -> _PrivateWrap[_T]: ...
|
|
75
75
|
|
|
76
76
|
class PrivateAttrType(type):
|
|
77
77
|
"metaclass for private attributes"
|
|
78
78
|
def __new__(cls, name: str, bases: tuple,
|
|
79
|
-
attrs:
|
|
79
|
+
attrs: _PrivateAttrDict, /,
|
|
80
80
|
private_func: Callable[[int, str], str]|None = None) -> PrivateAttrType: ...
|
|
81
81
|
|
|
82
82
|
class PrivateAttrBase(metaclass=PrivateAttrType):
|
|
@@ -95,7 +95,7 @@ class _PrivateTemp:
|
|
|
95
95
|
@property
|
|
96
96
|
def kwds(self) -> dict[str, Any]: ...
|
|
97
97
|
|
|
98
|
-
def prepare(name: str, bases: tuple, attrs:
|
|
98
|
+
def prepare(name: str, bases: tuple, attrs: _PrivateAttrDict, /, **kwds) -> _PrivateTemp:
|
|
99
99
|
"""
|
|
100
100
|
function for custom metaclass to create private attributes class.
|
|
101
101
|
|
{private_attribute_cpp-1.4.2 → private_attribute_cpp-1.4.4/private_attribute_cpp.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: private_attribute_cpp
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.4
|
|
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
|
|
@@ -19,7 +19,7 @@ readme = open('README.md').read()
|
|
|
19
19
|
|
|
20
20
|
setup(
|
|
21
21
|
name='private_attribute_cpp',
|
|
22
|
-
version='1.4.
|
|
22
|
+
version='1.4.4',
|
|
23
23
|
author="HuangHaoHua",
|
|
24
24
|
author_email="13140752715@example.com",
|
|
25
25
|
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
|