private-attribute-cpp 2.1.8__tar.gz → 2.1.10__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.8/private_attribute_cpp.egg-info → private_attribute_cpp-2.1.10}/PKG-INFO +1 -1
  2. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/private_attribute.cpp +28 -27
  3. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/private_attribute.pyi +15 -4
  4. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10/private_attribute_cpp.egg-info}/PKG-INFO +1 -1
  5. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/setup.py +1 -1
  6. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/LICENSE +0 -0
  7. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/MANIFEST.in +0 -0
  8. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/README.md +0 -0
  9. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/picosha2.h +0 -0
  10. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/private_attribute_cpp.egg-info/SOURCES.txt +0 -0
  11. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/private_attribute_cpp.egg-info/dependency_links.txt +0 -0
  12. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/private_attribute_cpp.egg-info/not-zip-safe +0 -0
  13. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/private_attribute_cpp.egg-info/top_level.txt +0 -0
  14. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/setup.cfg +0 -0
  15. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/tests/test_attr_classify_owner.py +0 -0
  16. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/tests/test_class_private_attrs.py +0 -0
  17. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/tests/test_gc_collect.py +0 -0
  18. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/tests/test_private_abc.py +0 -0
  19. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/tests/test_private_attrs.py +0 -0
  20. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/tests/test_private_func.py +0 -0
  21. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/tests/test_private_inheritance.py +0 -0
  22. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/tests/test_private_method.py +0 -0
  23. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/tests/test_private_wrap.py +0 -0
  24. {private_attribute_cpp-2.1.8 → private_attribute_cpp-2.1.10}/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.8
3
+ Version: 2.1.10
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);
@@ -2885,9 +2889,22 @@ ensure_tp(PyTypeObject* type_instance) noexcept
2885
2889
  static void
2886
2890
  ensure_subclass_tp(PyTypeObject* type_instance) noexcept
2887
2891
  {
2892
+ KeepPythonException _;
2888
2893
  PyObject* subclasses = PyObject_CallMethod((PyObject*)&PyType_Type, "__subclasses__", "O", (PyObject*)type_instance);
2889
- assert(subclasses);
2890
- assert(PyList_Check(subclasses));
2894
+ if (!subclasses) {
2895
+ PyObject* unraisable_missing = PyUnicode_FromString("type.__subclasses__()");
2896
+ PyErr_WriteUnraisable(unraisable_missing);
2897
+ Py_DECREF(unraisable_missing);
2898
+ return;
2899
+ }
2900
+ if (!PyList_Check(subclasses)) {
2901
+ PyErr_SetString(PyExc_TypeError, "type.__subclasses__() did not return a list");
2902
+ PyObject* unraisable_missing = PyUnicode_FromString("type.__subclasses__()");
2903
+ PyErr_WriteUnraisable(unraisable_missing);
2904
+ Py_DECREF(unraisable_missing);
2905
+ Py_DECREF(subclasses);
2906
+ return;
2907
+ }
2891
2908
  Py_ssize_t list_len = PyList_GET_SIZE(subclasses);
2892
2909
  for (Py_ssize_t i = 0; i < list_len; i++) {
2893
2910
  PyObject* subclass = PyList_GetItem(subclasses, i);
@@ -4271,36 +4288,20 @@ atexit_register_clean_func(void) noexcept
4271
4288
  if (!atexit) {
4272
4289
  return -1;
4273
4290
  }
4274
- PyObject* register_func = PyObject_GetAttrString(atexit, "register");
4275
- if (!register_func) {
4276
- Py_DECREF(atexit);
4277
- return -1;
4278
- }
4279
4291
 
4280
4292
  PyObject* func = PyCFunction_New(&clean_storage, NULL);
4281
4293
  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
4294
  Py_DECREF(atexit);
4291
4295
  return -1;
4292
4296
  }
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);
4297
+
4298
+ PyObject* result = PyObject_CallMethod(atexit, "register", "O", func);
4299
+ Py_DECREF(func);
4300
+ Py_DECREF(atexit);
4301
+
4302
+ if (!result) {
4299
4303
  return -1;
4300
4304
  }
4301
- Py_DECREF(args);
4302
- Py_DECREF(register_func);
4303
- Py_DECREF(atexit);
4304
4305
  Py_DECREF(result);
4305
4306
  return 0;
4306
4307
  }
@@ -15,14 +15,14 @@ class MyClass(PrivateAttrBase):
15
15
  return self._private_attr1
16
16
  ```
17
17
  """
18
- from typing import Any, TypeVar, Callable, TypedDict, Sequence, Generic, Optional
18
+ from typing import Any, TypeVar, Callable, TypedDict, Sequence, Generic, Optional, cast
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
22
  class _PrivateAttrDict(TypedDict):
23
23
  __private_attrs__: Optional[Sequence[str]]
24
24
 
25
- _T = TypeVar('T')
25
+ _T = TypeVar('_T')
26
26
 
27
27
  class _PrivateWrap(Generic[_T]):
28
28
  @property
@@ -38,9 +38,20 @@ class _PrivateWrap(Generic[_T]):
38
38
  def __getattr__(self, name: str) -> Any:
39
39
  return getattr(self.result, name)
40
40
 
41
- _TVar = TypeVar('TVar')
41
+ def __call__(self, *args: Any, **kwargs: Any) -> Any:
42
+ if callable(self.result):
43
+ return self.result(*args, **kwargs)
44
+ raise TypeError(f'{self.result!r} is not callable')
42
45
 
43
- class PrivateWrapProxy:
46
+ def __get__(self, instance: Any, owner: type) -> Any:
47
+ if hasattr(self.result, "__get__"):
48
+ descriptor = cast(Any, self.result)
49
+ return descriptor.__get__(instance, owner)
50
+ return self.result
51
+
52
+ _TVar = TypeVar('_TVar')
53
+
54
+ class PrivateWrapProxy(Generic[_TVar, _T]):
44
55
  """
45
56
  PrivateWrapProxy is a proxy for private attributes.
46
57
  Usage:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: private_attribute_cpp
3
- Version: 2.1.8
3
+ Version: 2.1.10
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.8',
27
+ version='2.1.10',
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.',