private-attribute-cpp 1.4.9__tar.gz → 1.4.11__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.
Files changed (21) hide show
  1. {private_attribute_cpp-1.4.9/private_attribute_cpp.egg-info → private_attribute_cpp-1.4.11}/PKG-INFO +2 -1
  2. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/README.md +1 -0
  3. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/private_attribute.cpp +80 -52
  4. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/private_attribute.pyi +1 -1
  5. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11/private_attribute_cpp.egg-info}/PKG-INFO +2 -1
  6. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/setup.py +1 -1
  7. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/LICENSE +0 -0
  8. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/MANIFEST.in +0 -0
  9. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/picosha2.h +0 -0
  10. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/private_attribute_cpp.egg-info/SOURCES.txt +0 -0
  11. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/private_attribute_cpp.egg-info/dependency_links.txt +0 -0
  12. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/private_attribute_cpp.egg-info/not-zip-safe +0 -0
  13. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/private_attribute_cpp.egg-info/top_level.txt +0 -0
  14. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/setup.cfg +0 -0
  15. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/tests/test_class_private_attrs.py +0 -0
  16. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/tests/test_private_abc.py +0 -0
  17. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/tests/test_private_attrs.py +0 -0
  18. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/tests/test_private_func.py +0 -0
  19. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/tests/test_private_inheritance.py +0 -0
  20. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/tests/test_private_method.py +0 -0
  21. {private_attribute_cpp-1.4.9 → private_attribute_cpp-1.4.11}/tests/test_private_wrap.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: private_attribute_cpp
3
- Version: 1.4.9
3
+ Version: 1.4.11
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
@@ -247,6 +247,7 @@ TypeError: Can't instantiate abstract class MyClass without an implementation fo
247
247
  - All of the object that is the instance of the class "PrivateAttrBase" or its subclass are default to be unable to be pickled.
248
248
  - Finally the attributes' names in `__private_attrs__` will be change to a tuple with two hash.
249
249
  - Finally the `_PrivateWrap` object will be recoveried to the original object.
250
+ - Don't use a decorator which will return the `_PrivateWrap` in `PrivateWrapProxy` which will raise `TypeError`.
250
251
  - One class defined in another class cannot use another class's private attribute.
251
252
  - One parent class defined an attribute which not in `__private_attrs__` or not a `PrivateAttrType` instance, the child class shouldn't contain the attribute in its `__private_attrs__`.
252
253
  - CPython may change "tp_getattro", "tp_setattro" and so on when you change the attribute "\_\_getattribute\_\_", "\_\_setattr\_\_" and so on. If you are fear about it, you can use `ensure_type` to reset those tp slots. For the other metaclasses, you can use `ensure_metaclass` to reset those tp slots. Also, don't set those methods on these classes in your code.
@@ -228,6 +228,7 @@ TypeError: Can't instantiate abstract class MyClass without an implementation fo
228
228
  - All of the object that is the instance of the class "PrivateAttrBase" or its subclass are default to be unable to be pickled.
229
229
  - Finally the attributes' names in `__private_attrs__` will be change to a tuple with two hash.
230
230
  - Finally the `_PrivateWrap` object will be recoveried to the original object.
231
+ - Don't use a decorator which will return the `_PrivateWrap` in `PrivateWrapProxy` which will raise `TypeError`.
231
232
  - One class defined in another class cannot use another class's private attribute.
232
233
  - One parent class defined an attribute which not in `__private_attrs__` or not a `PrivateAttrType` instance, the child class shouldn't contain the attribute in its `__private_attrs__`.
233
234
  - CPython may change "tp_getattro", "tp_setattro" and so on when you change the attribute "\_\_getattribute\_\_", "\_\_setattr\_\_" and so on. If you are fear about it, you can use `ensure_type` to reset those tp slots. For the other metaclasses, you can use `ensure_metaclass` to reset those tp slots. Also, don't set those methods on these classes in your code.
@@ -271,10 +271,7 @@ default_random_string(uintptr_t obj_id, const std::string& attr_name) noexcept
271
271
  result = it->second;
272
272
  return result;
273
273
  }
274
- while (true) {
275
- if (::AllData::all_exist_name.find(result) == ::AllData::all_exist_name.end()) {
276
- break;
277
- }
274
+ while (::AllData::all_exist_name.find(result) != ::AllData::all_exist_name.end()) {
278
275
  result = original_result + "_" + std::to_string(i);
279
276
  i++;
280
277
  }
@@ -372,10 +369,7 @@ custom_random_string(uintptr_t obj_id, const std::string& attr_name, PyObject* f
372
369
  result = it->second;
373
370
  return result;
374
371
  }
375
- while (true) {
376
- if (::AllData::all_exist_name.find(result) == ::AllData::all_exist_name.end()) {
377
- break;
378
- }
372
+ while (::AllData::all_exist_name.find(result) != ::AllData::all_exist_name.end()) {
379
373
  result = original_result + "_" + std::to_string(i);
380
374
  i++;
381
375
  }
@@ -883,17 +877,11 @@ static PrivateWrapObject* PrivateWrap_New(PyObject *decorator, PyObject *func, P
883
877
  static void PrivateWrap_dealloc(PrivateWrapObject *self) noexcept;
884
878
  static PyObject* PrivateWrap_call(PrivateWrapObject *self, PyObject *args, PyObject *kw) noexcept;
885
879
 
886
- static PyObject *
887
- PrivateWrap_result(PyObject *obj, void* /*closure*/) noexcept
888
- {
889
- if (!obj) {
890
- Py_RETURN_NONE;
891
- }
892
-
893
- PyObject *res = ((PrivateWrapObject*)obj)->result;
894
- Py_INCREF(res);
895
- return res;
896
- }
880
+ static PyMemberDef PrivateWrap_members[] = {
881
+ {"result", T_OBJECT, offsetof(PrivateWrapObject, result), READONLY, "The result object"},
882
+ {"__wrapped__", T_OBJECT, offsetof(PrivateWrapObject, result), READONLY, "The result object"},
883
+ {NULL}
884
+ };
897
885
 
898
886
  static PyObject *
899
887
  PrivateWrap_funcs(PyObject *obj, void* /*closure*/) noexcept
@@ -995,9 +983,7 @@ static const char* PrivateWrap_result_doc = "the final result of decorating";
995
983
  static const char* PrivateWrap_funcs_doc = "the original functions";
996
984
 
997
985
  static PyGetSetDef PrivateWrap_getset[] = {
998
- {"result", (getter)PrivateWrap_result, NULL, PrivateWrap_result_doc, NULL},
999
986
  {"funcs", (getter)PrivateWrap_funcs, NULL, PrivateWrap_funcs_doc, NULL},
1000
- {"__wrapped__", (getter)PrivateWrap_result, NULL, NULL, NULL},
1001
987
  {"__doc__", (getter)PrivateWrap_doc, NULL, NULL, NULL},
1002
988
  {"__module__", (getter)PrivateWrap_module, NULL, NULL, NULL},
1003
989
  {"__name__", (getter)PrivateWarp_name, NULL, NULL, NULL},
@@ -1050,21 +1036,25 @@ static PyTypeObject PrivateWrapType = {
1050
1036
  0, // tp_iter
1051
1037
  0, // tp_iternext
1052
1038
  0, // tp_methods
1053
- 0, // tp_members
1039
+ PrivateWrap_members, // tp_members
1054
1040
  PrivateWrap_getset, // tp_getset
1055
1041
  };
1056
1042
 
1057
1043
  static PrivateWrapObject*
1058
1044
  PrivateWrap_New(PyObject *decorator, PyObject *func, PyObject *list) noexcept
1059
1045
  {
1060
- PrivateWrapObject *self =
1061
- PyObject_New(PrivateWrapObject, &PrivateWrapType);
1062
1046
  PyObject *wrapped = PyObject_CallFunctionObjArgs(decorator, func, NULL);
1063
1047
  if (!wrapped) {
1064
- Py_DECREF(self);
1048
+ return NULL;
1049
+ }
1050
+ if (PyObject_TypeCheck(wrapped, &PrivateWrapType)) {
1051
+ PyErr_SetString(PyExc_TypeError, "decorator returned a '_PrivateWrap' object which is not allowed");
1052
+ Py_DECREF(wrapped);
1065
1053
  return NULL;
1066
1054
  }
1067
1055
 
1056
+ PrivateWrapObject *self =
1057
+ PyObject_New(PrivateWrapObject, &PrivateWrapType);
1068
1058
  self->func_list = list;
1069
1059
  Py_INCREF(list);
1070
1060
 
@@ -2891,8 +2881,7 @@ PrivateTempObject_kwds(PyObject* self, void* /*closure*/) noexcept
2891
2881
  {
2892
2882
  PyObject* kwds = ((PrivateTempObject*)self)->tmp->base_kwds;
2893
2883
  if (!kwds) {
2894
- PyErr_SetString(PyExc_RuntimeError, "object not init or have been used");
2895
- return nullptr;
2884
+ return PyDict_New();
2896
2885
  }
2897
2886
  Py_INCREF(kwds);
2898
2887
  return kwds;
@@ -3141,14 +3130,14 @@ PrivateModule_dir(PyObject* self, PyObject* /*args*/) noexcept
3141
3130
  Py_DECREF(parent_dir);
3142
3131
  return NULL;
3143
3132
  }
3144
- PyList_Append(attr_list, PyUnicode_FromString("PrivateWrapProxy"));
3145
- PyList_Append(attr_list, PyUnicode_FromString("PrivateAttrType"));
3146
- PyList_Append(attr_list, PyUnicode_FromString("PrivateAttrBase"));
3147
- PyList_Append(attr_list, PyUnicode_FromString("prepare"));
3148
- PyList_Append(attr_list, PyUnicode_FromString("postprocess"));
3149
- PyList_Append(attr_list, PyUnicode_FromString("register_metaclass"));
3150
- PyList_Append(attr_list, PyUnicode_FromString("ensure_type"));
3151
- PyList_Append(attr_list, PyUnicode_FromString("ensure_metaclass"));
3133
+ PyList_Append(attr_list, PyUnicode_InternFromString("PrivateWrapProxy"));
3134
+ PyList_Append(attr_list, PyUnicode_InternFromString("PrivateAttrType"));
3135
+ PyList_Append(attr_list, PyUnicode_InternFromString("PrivateAttrBase"));
3136
+ PyList_Append(attr_list, PyUnicode_InternFromString("prepare"));
3137
+ PyList_Append(attr_list, PyUnicode_InternFromString("postprocess"));
3138
+ PyList_Append(attr_list, PyUnicode_InternFromString("register_metaclass"));
3139
+ PyList_Append(attr_list, PyUnicode_InternFromString("ensure_type"));
3140
+ PyList_Append(attr_list, PyUnicode_InternFromString("ensure_metaclass"));
3152
3141
  PyObject* result = PySequence_Concat(parent_dir, attr_list);
3153
3142
  Py_DECREF(parent_dir);
3154
3143
  Py_DECREF(attr_list);
@@ -3168,13 +3157,6 @@ PrivateModule_setattro(PyObject* cls, PyObject* name, PyObject* value) noexcept
3168
3157
  return PyObject_GenericSetAttr(cls, name, value);
3169
3158
  }
3170
3159
 
3171
- static PyGetSetDef PrivateModule_getsetters[] = {
3172
- {"PrivateWrapProxy", (getter)PrivateModule_get_PrivateWrapProxy, NULL, NULL, NULL},
3173
- {"PrivateAttrType", (getter)PrivateModule_get_PrivateAttrType, NULL, NULL, NULL},
3174
- {"PrivateAttrBase", (getter)PrivateModule_get_PrivateAttrBase, NULL, NULL, NULL},
3175
- {NULL}
3176
- };
3177
-
3178
3160
  static const char* prepare_and_postprocess_doc = R"(function for custom metaclass to create private attributes class.
3179
3161
 
3180
3162
  def prepare(name: str, bases: tuple, attrs: dict, **kwds) -> tempobject:
@@ -3214,7 +3196,6 @@ def ensure_metaclass(metaclass: type) -> None:
3214
3196
  )";
3215
3197
 
3216
3198
  static PyMethodDef PrivateModule_methods[] = {
3217
- {"__dir__", (PyCFunction)PrivateModule_dir, METH_NOARGS, NULL},
3218
3199
  {"prepare", (PyCFunction)prepare_for_PrivateAttr, METH_VARARGS | METH_KEYWORDS | METH_STATIC, prepare_and_postprocess_doc},
3219
3200
  {"postprocess", (PyCFunction)postprocess_for_PrivateAttr, METH_VARARGS | METH_STATIC, prepare_and_postprocess_doc},
3220
3201
  {"register_metaclass", (PyCFunction)register_metaclass, METH_O | METH_STATIC, prepare_and_postprocess_doc},
@@ -3223,6 +3204,53 @@ static PyMethodDef PrivateModule_methods[] = {
3223
3204
  {NULL} // Sentinel
3224
3205
  };
3225
3206
 
3207
+ static PyObject*
3208
+ PrivateModule_get_prepare(PyObject* /*self*/, void* /*closure*/) noexcept
3209
+ {
3210
+ return PyCFunction_NewEx(&PrivateModule_methods[0], NULL, NULL);
3211
+ }
3212
+
3213
+ static PyObject*
3214
+ PrivateModule_get_postprocess(PyObject* /*self*/, void* /*closure*/) noexcept
3215
+ {
3216
+ return PyCFunction_NewEx(&PrivateModule_methods[1], NULL, NULL);
3217
+ }
3218
+
3219
+ static PyObject*
3220
+ PrivateModule_get_register_metaclass(PyObject* /*self*/, void* /*closure*/) noexcept
3221
+ {
3222
+ return PyCFunction_NewEx(&PrivateModule_methods[2], NULL, NULL);
3223
+ }
3224
+
3225
+ static PyObject*
3226
+ PrivateModule_get_ensure_type(PyObject* /*self*/, void* /*closure*/) noexcept
3227
+ {
3228
+ return PyCFunction_NewEx(&PrivateModule_methods[3], NULL, NULL);
3229
+ }
3230
+
3231
+ static PyObject*
3232
+ PrivateModule_get_ensure_metaclass(PyObject* /*self*/, void* /*closure*/) noexcept
3233
+ {
3234
+ return PyCFunction_NewEx(&PrivateModule_methods[4], NULL, NULL);
3235
+ }
3236
+
3237
+ static PyGetSetDef PrivateModule_getsetters[] = {
3238
+ {"PrivateWrapProxy", (getter)PrivateModule_get_PrivateWrapProxy, NULL, NULL, NULL},
3239
+ {"PrivateAttrType", (getter)PrivateModule_get_PrivateAttrType, NULL, NULL, NULL},
3240
+ {"PrivateAttrBase", (getter)PrivateModule_get_PrivateAttrBase, NULL, NULL, NULL},
3241
+ {"prepare", (getter)PrivateModule_get_prepare, NULL, NULL, NULL},
3242
+ {"postprocess", (getter)PrivateModule_get_postprocess, NULL, NULL, NULL},
3243
+ {"register_metaclass", (getter)PrivateModule_get_register_metaclass, NULL, NULL, NULL},
3244
+ {"ensure_type", (getter)PrivateModule_get_ensure_type, NULL, NULL, NULL},
3245
+ {"ensure_metaclass", (getter)PrivateModule_get_ensure_metaclass, NULL, NULL, NULL},
3246
+ {NULL}
3247
+ };
3248
+
3249
+ static PyMethodDef PrivateModule_methods_def[] = {
3250
+ {"__dir__", (PyCFunction)PrivateModule_dir, METH_NOARGS, NULL},
3251
+ {NULL} // Sentinel
3252
+ };
3253
+
3226
3254
  static PyTypeObject PrivateModuleType = {
3227
3255
  PyVarObject_HEAD_INIT(NULL, 0)
3228
3256
  "private_attribute_module", //tp_name
@@ -3251,7 +3279,7 @@ static PyTypeObject PrivateModuleType = {
3251
3279
  0, //tp_weaklistoffset
3252
3280
  0, //tp_iter
3253
3281
  0, //tp_iternext
3254
- PrivateModule_methods, //tp_methods
3282
+ PrivateModule_methods_def, //tp_methods
3255
3283
  0, //tp_members
3256
3284
  PrivateModule_getsetters, //tp_getset
3257
3285
  &PyModule_Type, //tp_base
@@ -3323,14 +3351,14 @@ PyInit_private_attribute(void) noexcept
3323
3351
  * ensure_type
3324
3352
  * ensure_metaclass
3325
3353
  */
3326
- PyList_Append(all, PyUnicode_FromString("PrivateWrapProxy"));
3327
- PyList_Append(all, PyUnicode_FromString("PrivateAttrType"));
3328
- PyList_Append(all, PyUnicode_FromString("PrivateAttrBase"));
3329
- PyList_Append(all, PyUnicode_FromString("prepare"));
3330
- PyList_Append(all, PyUnicode_FromString("postprocess"));
3331
- PyList_Append(all, PyUnicode_FromString("register_metaclass"));
3332
- PyList_Append(all, PyUnicode_FromString("ensure_type"));
3333
- PyList_Append(all, PyUnicode_FromString("ensure_metaclass"));
3354
+ PyList_Append(all, PyUnicode_InternFromString("PrivateWrapProxy"));
3355
+ PyList_Append(all, PyUnicode_InternFromString("PrivateAttrType"));
3356
+ PyList_Append(all, PyUnicode_InternFromString("PrivateAttrBase"));
3357
+ PyList_Append(all, PyUnicode_InternFromString("prepare"));
3358
+ PyList_Append(all, PyUnicode_InternFromString("postprocess"));
3359
+ PyList_Append(all, PyUnicode_InternFromString("register_metaclass"));
3360
+ PyList_Append(all, PyUnicode_InternFromString("ensure_type"));
3361
+ PyList_Append(all, PyUnicode_InternFromString("ensure_metaclass"));
3334
3362
  Py_SET_TYPE(m, &PrivateModuleType);
3335
3363
  return m;
3336
3364
  }
@@ -76,7 +76,7 @@ class PrivateWrapProxy:
76
76
  class PrivateAttrType(type):
77
77
  "metaclass for private attributes"
78
78
  def __new__(cls, name: str, bases: tuple,
79
- attrs: _PrivateAttrDict, /,
79
+ attrs: _PrivateAttrDict, /, *,
80
80
  private_func: Callable[[int, str], str]|None = None) -> PrivateAttrType: ...
81
81
 
82
82
  class PrivateAttrBase(metaclass=PrivateAttrType):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: private_attribute_cpp
3
- Version: 1.4.9
3
+ Version: 1.4.11
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
@@ -247,6 +247,7 @@ TypeError: Can't instantiate abstract class MyClass without an implementation fo
247
247
  - All of the object that is the instance of the class "PrivateAttrBase" or its subclass are default to be unable to be pickled.
248
248
  - Finally the attributes' names in `__private_attrs__` will be change to a tuple with two hash.
249
249
  - Finally the `_PrivateWrap` object will be recoveried to the original object.
250
+ - Don't use a decorator which will return the `_PrivateWrap` in `PrivateWrapProxy` which will raise `TypeError`.
250
251
  - One class defined in another class cannot use another class's private attribute.
251
252
  - One parent class defined an attribute which not in `__private_attrs__` or not a `PrivateAttrType` instance, the child class shouldn't contain the attribute in its `__private_attrs__`.
252
253
  - CPython may change "tp_getattro", "tp_setattro" and so on when you change the attribute "\_\_getattribute\_\_", "\_\_setattr\_\_" and so on. If you are fear about it, you can use `ensure_type` to reset those tp slots. For the other metaclasses, you can use `ensure_metaclass` to reset those tp slots. Also, don't set those methods on these classes in your code.
@@ -18,7 +18,7 @@ readme = open('README.md').read()
18
18
 
19
19
  setup(
20
20
  name='private_attribute_cpp',
21
- version='1.4.9',
21
+ version='1.4.11',
22
22
  author="HuangHaoHua",
23
23
  author_email="13140752715@example.com",
24
24
  description='A Python package that provides a way to define private attributes in C++ implementation.',