private-attribute-cpp 2.0.2__tar.gz → 2.0.3__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-2.0.2/private_attribute_cpp.egg-info → private_attribute_cpp-2.0.3}/PKG-INFO +1 -1
  2. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/private_attribute.cpp +41 -32
  3. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3/private_attribute_cpp.egg-info}/PKG-INFO +1 -1
  4. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/setup.py +1 -1
  5. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/LICENSE +0 -0
  6. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/MANIFEST.in +0 -0
  7. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/README.md +0 -0
  8. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/picosha2.h +0 -0
  9. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/private_attribute.pyi +0 -0
  10. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/private_attribute_cpp.egg-info/SOURCES.txt +0 -0
  11. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/private_attribute_cpp.egg-info/dependency_links.txt +0 -0
  12. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/private_attribute_cpp.egg-info/not-zip-safe +0 -0
  13. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/private_attribute_cpp.egg-info/top_level.txt +0 -0
  14. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/setup.cfg +0 -0
  15. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/tests/test_class_private_attrs.py +0 -0
  16. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/tests/test_private_abc.py +0 -0
  17. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/tests/test_private_attrs.py +0 -0
  18. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/tests/test_private_func.py +0 -0
  19. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/tests/test_private_inheritance.py +0 -0
  20. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/tests/test_private_method.py +0 -0
  21. {private_attribute_cpp-2.0.2 → private_attribute_cpp-2.0.3}/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: 2.0.2
3
+ Version: 2.0.3
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
@@ -476,9 +476,7 @@ id_getattr(const std::string& attr_name, PyObject* obj, PyObject* typ) noexcept
476
476
  if (type_name == NULL) {
477
477
  return NULL;
478
478
  }
479
- std::string string_type_name = type_name;
480
- std::string exception_information = "'" + string_type_name + "' objects has no attribute '" + attr_name + "'";
481
- PyErr_SetString(PyExc_AttributeError, exception_information.c_str());
479
+ PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%s'", type_name, attr_name.c_str());
482
480
  return NULL;
483
481
  }
484
482
 
@@ -510,9 +508,7 @@ type_getattr(PyObject* typ, const std::string& attr_name) noexcept
510
508
  if (type_name == NULL) {
511
509
  return NULL;
512
510
  }
513
- std::string string_type_name = type_name;
514
- std::string message = "type object '" + string_type_name + "' has no attribute '" + attr_name + "'";
515
- PyErr_SetString(PyExc_AttributeError, message.c_str());
511
+ PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%s'", type_name, attr_name.c_str());
516
512
  return NULL;
517
513
  }
518
514
 
@@ -723,10 +719,7 @@ id_delattr(const std::string& attr_name, PyObject* obj, PyObject* typ) noexcept
723
719
  if (type_name == NULL) {
724
720
  return -1;
725
721
  }
726
- std::string string_type_name = type_name;
727
- std::string exception_information = "'" + string_type_name + "' objects has no attribute '" + attr_name + "'";
728
- PyErr_SetString(PyExc_AttributeError, exception_information.c_str());
729
- return -1;
722
+ PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%s'", type_name, attr_name.c_str());
730
723
  }
731
724
  PyObject* delete_obj = ::AllData::all_object_attr[final_id][obj_id][obj_private_name];
732
725
  ::AllData::all_object_attr[final_id][obj_id].erase(obj_private_name);
@@ -774,9 +767,7 @@ type_delattr(PyObject* typ, const std::string& attr_name) noexcept
774
767
  if (type_name == NULL) {
775
768
  return -1;
776
769
  }
777
- std::string string_type_name = type_name;
778
- std::string message = "type object '" + string_type_name + "' has no attribute '" + attr_name + "'";
779
- PyErr_SetString(PyExc_AttributeError, message.c_str());
770
+ PyErr_Format(PyExc_AttributeError, "type object '%s' has no attribute '%s'", type_name, attr_name.c_str());
780
771
  return -1;
781
772
  }
782
773
  PyObject* delete_obj = ::AllData::type_attr_dict[typ_id][final_key];
@@ -802,9 +793,7 @@ type_delattr(PyObject* typ, const std::string& attr_name) noexcept
802
793
  if (type_name == NULL) {
803
794
  return -1;
804
795
  }
805
- std::string string_type_name = type_name;
806
- std::string message = "type object '" + string_type_name + "' has no attribute '" + attr_name + "'";
807
- PyErr_SetString(PyExc_AttributeError, message.c_str());
796
+ PyErr_Format(PyExc_AttributeError, "type object '%s' has no attribute '%s'", type_name, attr_name.c_str());
808
797
  return -1;
809
798
  }
810
799
  PyObject* delete_obj = ::AllData::all_type_subclass_attr[final_id][typ_id][final_key];
@@ -1937,26 +1926,46 @@ PrivateAttrType_preprocess(PyObject* args, PyObject* kwds, PrivateAttrCreationDa
1937
1926
 
1938
1927
  if (has_slots) {
1939
1928
  PyObject* all_slots = PyDict_GetItemString(data.attrs_copy, "__slots__");
1940
- PyObject* slot_seq = PySequence_Fast(all_slots, "__slots__ must be a sequence");
1941
- if (!slot_seq) {
1942
- return false;
1943
- }
1944
-
1945
- Py_ssize_t slot_len = PySequence_Fast_GET_SIZE(slot_seq);
1946
-
1947
- for (Py_ssize_t j = 0; j < slot_len; j++) {
1948
- PyObject* slot = PySequence_Fast_GET_ITEM(slot_seq, j);
1949
- if (PyUnicode_Check(slot)) {
1950
- const char* slot_cstr = PyUnicode_AsUTF8(slot);
1951
- if (data.private_attrs_vector_string.find((std::string)slot_cstr) != data.private_attrs_vector_string.end()){
1952
- std::string error_msg = "'__slots__' and '__private_attrs__' cannot have the same attribute name: '" + std::string(slot_cstr) + "'";
1953
- PyErr_SetString(PyExc_TypeError, error_msg.c_str());
1954
- Py_DECREF(slot_seq);
1929
+ if (!all_slots) {return false;}
1930
+ if (PyUnicode_Check(all_slots)) {
1931
+ const char* slot_cstr = PyUnicode_AsUTF8(all_slots);
1932
+ if (data.private_attrs_vector_string.find((std::string)slot_cstr) != data.private_attrs_vector_string.end()){
1933
+ std::string error_msg = "'__slots__' and '__private_attrs__' cannot have the same attribute name: '" + std::string(slot_cstr) + "'";
1934
+ PyErr_SetString(PyExc_TypeError, error_msg.c_str());
1935
+ return false;
1936
+ }
1937
+ } else {
1938
+ PyObject* slot_seq;
1939
+ if (PyAnyDict_Check(all_slots)) {
1940
+ // use the key of the dict as the slot name
1941
+ PyObject* keys = PyDict_Keys(all_slots);
1942
+ if (!keys) {
1955
1943
  return false;
1956
1944
  }
1945
+ slot_seq = keys;
1946
+ } else {
1947
+ slot_seq = PySequence_Fast(all_slots, "__slots__ must be a sequence");
1948
+ }
1949
+ if (!slot_seq) {
1950
+ return false;
1951
+ }
1952
+
1953
+ Py_ssize_t slot_len = PySequence_Fast_GET_SIZE(slot_seq);
1954
+
1955
+ for (Py_ssize_t j = 0; j < slot_len; j++) {
1956
+ PyObject* slot = PySequence_Fast_GET_ITEM(slot_seq, j);
1957
+ if (PyUnicode_Check(slot)) {
1958
+ const char* slot_cstr = PyUnicode_AsUTF8(slot);
1959
+ if (data.private_attrs_vector_string.find((std::string)slot_cstr) != data.private_attrs_vector_string.end()){
1960
+ std::string error_msg = "'__slots__' and '__private_attrs__' cannot have the same attribute name: '" + std::string(slot_cstr) + "'";
1961
+ PyErr_SetString(PyExc_TypeError, error_msg.c_str());
1962
+ Py_DECREF(slot_seq);
1963
+ return false;
1964
+ }
1965
+ }
1957
1966
  }
1967
+ Py_DECREF(slot_seq);
1958
1968
  }
1959
- Py_DECREF(slot_seq);
1960
1969
  }
1961
1970
 
1962
1971
  Py_ssize_t bases_len = PyTuple_GET_SIZE(data.bases);
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: private_attribute_cpp
3
- Version: 2.0.2
3
+ Version: 2.0.3
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
@@ -18,7 +18,7 @@ readme = open('README.md').read()
18
18
 
19
19
  setup(
20
20
  name='private_attribute_cpp',
21
- version='2.0.2',
21
+ version='2.0.3',
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.',