private-attribute-cpp 2.1.9__tar.gz → 2.1.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 (24) hide show
  1. {private_attribute_cpp-2.1.9/private_attribute_cpp.egg-info → private_attribute_cpp-2.1.11}/PKG-INFO +1 -1
  2. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/private_attribute.cpp +32 -28
  3. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11/private_attribute_cpp.egg-info}/PKG-INFO +1 -1
  4. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/setup.py +1 -1
  5. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/LICENSE +0 -0
  6. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/MANIFEST.in +0 -0
  7. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/README.md +0 -0
  8. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/picosha2.h +0 -0
  9. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/private_attribute.pyi +0 -0
  10. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/private_attribute_cpp.egg-info/SOURCES.txt +0 -0
  11. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/private_attribute_cpp.egg-info/dependency_links.txt +0 -0
  12. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/private_attribute_cpp.egg-info/not-zip-safe +0 -0
  13. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/private_attribute_cpp.egg-info/top_level.txt +0 -0
  14. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/setup.cfg +0 -0
  15. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/tests/test_attr_classify_owner.py +0 -0
  16. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/tests/test_class_private_attrs.py +0 -0
  17. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/tests/test_gc_collect.py +0 -0
  18. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/tests/test_private_abc.py +0 -0
  19. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/tests/test_private_attrs.py +0 -0
  20. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/tests/test_private_func.py +0 -0
  21. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/tests/test_private_inheritance.py +0 -0
  22. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/tests/test_private_method.py +0 -0
  23. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/tests/test_private_wrap.py +0 -0
  24. {private_attribute_cpp-2.1.9 → private_attribute_cpp-2.1.11}/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.9
3
+ Version: 2.1.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
@@ -1802,11 +1802,14 @@ PrivateAttr_tp_clear(PyObject* self) noexcept
1802
1802
 
1803
1803
  class KeepPythonException {
1804
1804
  private:
1805
- PyObject* typ;
1806
- PyObject* exc;
1807
- PyObject* tb;
1805
+ #if PY_VERSION_HEX < 0x030C0000
1806
+ PyObject* typ = NULL;
1807
+ PyObject* tb = NULL;
1808
+ #endif
1809
+ PyObject* exc = NULL;
1808
1810
  public:
1809
1811
  KeepPythonException() noexcept {
1812
+ if (PyErr_Occurred())
1810
1813
  // under 3.12 use PyErr_Fetch
1811
1814
  #if PY_VERSION_HEX < 0x030C0000
1812
1815
  PyErr_Fetch(&typ, &exc, &tb);
@@ -1816,6 +1819,7 @@ public:
1816
1819
  }
1817
1820
 
1818
1821
  ~KeepPythonException() noexcept {
1822
+ if (exc)
1819
1823
  // under 3.12 use PyErr_Restore
1820
1824
  #if PY_VERSION_HEX < 0x030C0000
1821
1825
  PyErr_Restore(typ, exc, tb);
@@ -2407,9 +2411,12 @@ analyse_all_code(PyObject* obj, std::unordered_map<uintptr_t, PyObjectStorage>&
2407
2411
  static std::string
2408
2412
  real_class_name(const std::string& name, const std::string& class_name) noexcept
2409
2413
  {
2414
+ size_t start_pos = class_name.find_first_not_of('_');
2415
+ std::string cleaned_class_name = (start_pos == std::string::npos) ? "" : class_name.substr(start_pos);
2416
+
2410
2417
  // if the name starts with "__" but does not end with "__", change to _ClassName__name
2411
2418
  if (name.length() >= 2 && name.substr(0, 2) == "__" && name.substr(name.length() - 2) != "__") {
2412
- return "_" + class_name + name;
2419
+ return "_" + cleaned_class_name + name;
2413
2420
  }
2414
2421
  return name;
2415
2422
  }
@@ -2885,9 +2892,22 @@ ensure_tp(PyTypeObject* type_instance) noexcept
2885
2892
  static void
2886
2893
  ensure_subclass_tp(PyTypeObject* type_instance) noexcept
2887
2894
  {
2895
+ KeepPythonException _;
2888
2896
  PyObject* subclasses = PyObject_CallMethod((PyObject*)&PyType_Type, "__subclasses__", "O", (PyObject*)type_instance);
2889
- assert(subclasses);
2890
- assert(PyList_Check(subclasses));
2897
+ if (!subclasses) {
2898
+ PyObject* unraisable_missing = PyUnicode_FromString("type.__subclasses__()");
2899
+ PyErr_WriteUnraisable(unraisable_missing);
2900
+ Py_DECREF(unraisable_missing);
2901
+ return;
2902
+ }
2903
+ if (!PyList_Check(subclasses)) {
2904
+ PyErr_SetString(PyExc_TypeError, "type.__subclasses__() did not return a list");
2905
+ PyObject* unraisable_missing = PyUnicode_FromString("type.__subclasses__()");
2906
+ PyErr_WriteUnraisable(unraisable_missing);
2907
+ Py_DECREF(unraisable_missing);
2908
+ Py_DECREF(subclasses);
2909
+ return;
2910
+ }
2891
2911
  Py_ssize_t list_len = PyList_GET_SIZE(subclasses);
2892
2912
  for (Py_ssize_t i = 0; i < list_len; i++) {
2893
2913
  PyObject* subclass = PyList_GetItem(subclasses, i);
@@ -4271,36 +4291,20 @@ atexit_register_clean_func(void) noexcept
4271
4291
  if (!atexit) {
4272
4292
  return -1;
4273
4293
  }
4274
- PyObject* register_func = PyObject_GetAttrString(atexit, "register");
4275
- if (!register_func) {
4276
- Py_DECREF(atexit);
4277
- return -1;
4278
- }
4279
4294
 
4280
4295
  PyObject* func = PyCFunction_New(&clean_storage, NULL);
4281
4296
  if (!func) {
4282
- Py_DECREF(register_func);
4283
- Py_DECREF(atexit);
4284
- return -1;
4285
- }
4286
- PyObject* args = PyTuple_New(1);
4287
- if (!args) {
4288
- Py_DECREF(func);
4289
- Py_DECREF(register_func);
4290
4297
  Py_DECREF(atexit);
4291
4298
  return -1;
4292
4299
  }
4293
- PyTuple_SET_ITEM(args, 0, func);
4294
- PyObject* result = PyObject_CallObject(register_func, args);
4295
- if (result == NULL) {
4296
- Py_DECREF(args);
4297
- Py_DECREF(register_func);
4298
- Py_DECREF(atexit);
4300
+
4301
+ PyObject* result = PyObject_CallMethod(atexit, "register", "O", func);
4302
+ Py_DECREF(func);
4303
+ Py_DECREF(atexit);
4304
+
4305
+ if (!result) {
4299
4306
  return -1;
4300
4307
  }
4301
- Py_DECREF(args);
4302
- Py_DECREF(register_func);
4303
- Py_DECREF(atexit);
4304
4308
  Py_DECREF(result);
4305
4309
  return 0;
4306
4310
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: private_attribute_cpp
3
- Version: 2.1.9
3
+ Version: 2.1.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
@@ -24,7 +24,7 @@ readme = open('README.md').read()
24
24
 
25
25
  setup(
26
26
  name='private_attribute_cpp',
27
- version='2.1.9',
27
+ version='2.1.11',
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.',