private-attribute-cpp 1.0.1__cp313-cp313-musllinux_1_2_x86_64.whl → 1.2.7__cp313-cp313-musllinux_1_2_x86_64.whl

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.pyi CHANGED
@@ -1,4 +1,5 @@
1
- from typing import Any, TypeVar, Callable, TypedDict, Sequence
1
+ from typing import Any, TypeVar, Callable, TypedDict, Sequence, Generic
2
+ from types import FunctionType
2
3
 
3
4
  # define the dict that must have a key "__private_attrs__" and value must be the sequence of strings
4
5
  class PrivateAttrDict(TypedDict):
@@ -6,13 +7,42 @@ class PrivateAttrDict(TypedDict):
6
7
 
7
8
  T = TypeVar('T')
8
9
 
9
- class _PrivateWrap[T]:
10
+ class _PrivateWrap(Generic[T]):
10
11
  @property
11
12
  def result(self) -> T: ...
12
13
 
14
+ @property
15
+ def funcs(self) -> tuple[FunctionType]: ...
16
+
17
+ def __getattr__(self, name: str) -> Any:
18
+ return getattr(self.result, name)
19
+
20
+ TVar = TypeVar('TVar')
21
+
13
22
  class PrivateWrapProxy:
14
- def __init__(self, decorator: Callable[[Any], T], orig: _PrivateWrap|None = None, /) -> None: ...
15
- def __call__(self, func: Any) -> _PrivateWrap[T]: ...
23
+ def __init__(self, decorator: Callable[[TVar], T], orig: _PrivateWrap[Any]|None = None, /) -> None: ...
24
+ def __call__(self, func: TVar, /) -> _PrivateWrap[T]: ...
16
25
 
17
26
  class PrivateAttrType(type):
18
- def __new__(cls, name: str, bases: tuple, attrs: PrivateAttrDict, private_func: Callable[[int, str], str]|None = None) -> PrivateAttrType: ...
27
+ def __new__(cls, name: str, bases: tuple,
28
+ attrs: PrivateAttrDict, /,
29
+ private_func: Callable[[int, str], str]|None = None) -> PrivateAttrType: ...
30
+
31
+ class PrivateAttrBase(metaclass=PrivateAttrType):
32
+ __slots__ = ()
33
+ __private_attrs__ = ()
34
+
35
+
36
+ class _PrivateTemp:
37
+ @property
38
+ def name(self) -> str: ...
39
+ @property
40
+ def bases(self) -> tuple[type]: ...
41
+ @property
42
+ def attrs(self) -> dict[str, Any]: ...
43
+ @property
44
+ def kwds(self) -> dict[str, Any]: ...
45
+
46
+ def prepare(name: str, bases: tuple, attrs: PrivateAttrDict, /, **kwds) -> _PrivateTemp: ...
47
+ def postprocess(typ: type, temp: _PrivateTemp, /) -> None: ...
48
+ def register_metaclass(typ: type, /) -> None: ...
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: private_attribute_cpp
3
- Version: 1.0.1
3
+ Version: 1.2.7
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
@@ -21,7 +21,7 @@ Dynamic: summary
21
21
 
22
22
  This package provide a way to create the private attribute like "C++" does.
23
23
 
24
- ## All API
24
+ ## All Base API
25
25
 
26
26
  ```python
27
27
  from private_attribute import (PrivateAttrBase, PrivateWrapProxy) # 1 Import public API
@@ -52,15 +52,9 @@ class MyClass(PrivateAttrBase, private_func=my_generate_func): # 3 Inherit +
52
52
  inner(...)
53
53
  return heavy_computation(self.a, self.b, self.c, x)
54
54
 
55
- @expensive_api_call.non_conflict_attr_name1 # 6 Easy access to internal names
56
- @expensive_api_call.non_conflict_attr_name2 # 6 Easy use when the name has no conflict
57
- @PrivateWrapProxy(lambda f: f) # 5 dummy wrapper just to restore order
58
- def expensive_api_call(self, x): # Second definition (will be wrapped)
59
- return heavy_computation(self.a, self.b, self.c, x)
60
-
61
55
  # Fix decorator order + resolve name conflicts
62
- @PrivateWrapProxy(expensive_api_call.result.conflicted_name2, expensive_api_call) # 7 Chain .result to push decorators down
63
- @PrivateWrapProxy(expensive_api_call.result.conflicted_name1, expensive_api_call) # 7 Resolve conflict with internal names
56
+ @PrivateWrapProxy(expensive_api_call.result.name2, expensive_api_call) # 6 Chain .result to push decorators down
57
+ @PrivateWrapProxy(expensive_api_call.result.name1, expensive_api_call) # 6 Resolve conflict with internal names
64
58
  def expensive_api_call(self, x): # Final real implementation
65
59
  return heavy_computation(self.a, self.b, self.c, x)
66
60
 
@@ -74,15 +68,14 @@ print(obj.expensive_api_call(10)) # works with all decorators applied
74
68
  ```
75
69
 
76
70
  | # | API | Purpose | Required? |
77
- |---|----------------------------------------|-------------------------------------------------------|-----------|
71
+ | --- | ---------------------------------------- | ------------------------------------------------------- | ----------- |
78
72
  | 1 | PrivateAttrBase | Base class – must inherit | Yes |
79
- | 1 | PrivateWrapProxy | Decorator wrapper for arbitrary decorators | When needed |
80
- | 2 | private_func=callable | Custom hidden-name generator | Optional |
81
- | 3 | Pass private_func in class definition | Same as above | Optional |
73
+ | 1 | PrivateWrapProxy | Decorator wrapper for arbitrary decorators | When needed |
74
+ | 2 | private_func=callable | Custom hidden-name generator | Optional |
75
+ | 3 | Pass private_func in class definition | Same as above | Optional |
82
76
  | 4 | \_\_private_attrs\_\_ list | Declare which attributes are private | Yes |
83
77
  | 5 | @PrivateWrapProxy(...) | Make any decorator compatible with private attributes | When needed |
84
- | 6 | method.xxx | Normal api name proxy | Based on its api |
85
- | 7 | method.result.xxx chain + dummy wrap | Fix decorator order and name conflicts | When needed |
78
+ | 6 | method.result.xxx chain + dummy wrap | Fix decorator order and name conflicts | When needed |
86
79
 
87
80
  ## Usage
88
81
 
@@ -145,8 +138,7 @@ class MyClass(PrivateAttrBase):
145
138
  def method1(self):
146
139
  ...
147
140
 
148
- @method1.attr_name
149
- @PrivateWrapProxy(lambda _: _) # use empty function to wrap
141
+ @PrivateWrapProxy(method1.attr_name, method1) # Use the argument "method1" to save old func
150
142
  def method1(self):
151
143
  ...
152
144
 
@@ -154,8 +146,7 @@ class MyClass(PrivateAttrBase):
154
146
  def method2(self):
155
147
  ...
156
148
 
157
- @method2.attr_name
158
- @PrivateWrapProxy(lambda _: _)
149
+ @PrivateWrapProxy(method2.attr_name, method2) # Use the argument "method2" to save old func
159
150
  def method2(self):
160
151
  ...
161
152
 
@@ -164,7 +155,7 @@ class MyClass(PrivateAttrBase):
164
155
 
165
156
  The `PrivateWrapProxy` is a decorator, and it will wrap the function with the decorator. When it decorates the method, it returns a `_PrivateWrap` object.
166
157
 
167
- The `_PrivateWrap` has the public api `result`. It returns the original decoratored result.
158
+ The `_PrivateWrap` has the public api `result` and `funcs`. `result` returns the original decoratored result and `funcs` returns the tuple of the original functions.
168
159
 
169
160
  ```python
170
161
  from private_attribute import PrivateAttrBase, PrivateWrapProxy
@@ -188,6 +179,63 @@ class MyClass(PrivateAttrBase):
188
179
  def method2(self):
189
180
  ```
190
181
 
182
+ ## Advanced API
183
+
184
+ ### define your metaclass based on one metaclass
185
+
186
+ You can define your metaclass based on one metaclass:
187
+
188
+ ```python
189
+ from abc import ABCMeta, abstractmethod
190
+ import private_attribute
191
+
192
+ class PrivateAbcMeta(ABCMeta):
193
+ def __new__(cls, name, bases, attrs, **kwargs):
194
+ temp = private_attribute.prepare(name, bases, attrs, **kwargs)
195
+ typ = super().__new__(cls, temp.name, temp.bases, temp.attrs, **temp.kwds)
196
+ private_attribute.postprocess(typ, temp)
197
+ return typ
198
+
199
+ private_attribute.register_metaclass(PrivateAbcMeta)
200
+ ```
201
+
202
+ By this way you create a metaclass both can behave as ABC and private attribute:
203
+
204
+ ```python
205
+ class MyClass(metaclass=PrivateAbcMeta):
206
+ __private_attrs__ = ()
207
+ __slots__ = ()
208
+
209
+ @abstractmethod
210
+ def my_function(self): ...
211
+
212
+ class MyImplement(MyClass):
213
+ __private_attrs__ = ("_a",)
214
+ def __init__(self, value=1):
215
+ self._a = value
216
+
217
+ def my_function(self):
218
+ return self._a
219
+ ```
220
+
221
+ Finally:
222
+
223
+ ```python
224
+ >>> a = MyImplement(1)
225
+ >>> a.my_function()
226
+ 1
227
+ >>> a._a
228
+ Traceback (most recent call last):
229
+ File "<pyshell#2>", line 1, in <module>
230
+ a._a
231
+ AttributeError: private attribute
232
+ >>> MyClass()
233
+ Traceback (most recent call last):
234
+ File "<pyshell#3>", line 1, in <module>
235
+ MyClass()
236
+ TypeError: Can't instantiate abstract class MyClass without an implementation for abstract method 'my_function'
237
+ ```
238
+
191
239
  ## Notes
192
240
 
193
241
  - All of the private attributes class must contain the `__private_attrs__` attribute.
@@ -206,7 +254,7 @@ MIT
206
254
 
207
255
  ## Requirement
208
256
 
209
- This package require the c++ module "picosha2" to compute the sha256 hash.
257
+ This package require the c++ module "[picosha2](https://github.com/okdshin/PicoSHA2)" to compute the sha256 hash.
210
258
 
211
259
  ## Support
212
260
 
@@ -0,0 +1,9 @@
1
+ private_attribute.cpython-313-x86_64-linux-musl.so,sha256=EAW49O3jhVY4Oecv-w8jp1YLHj5nrM-6RfQuEH8hPsQ,4392353
2
+ private_attribute.pyi,sha256=Ad6jEmPco-PJ4KKkim5aYKoxlfibn80SOu5GxhX6xIY,1492
3
+ private_attribute_cpp.libs/libgcc_s-0cd532bd.so.1,sha256=yPk0-VjyKzucjnkP3mvC0vVaua6Ln17qZUJbICcXgtA,181737
4
+ private_attribute_cpp.libs/libstdc++-5d72f927.so.6.0.33,sha256=fogxHsmB1_D6C-a_-uHh8Ei_6Qh52a8vLlicJRM3ehk,3562401
5
+ private_attribute_cpp-1.2.7.dist-info/METADATA,sha256=2QiaxmVdeD-EAgoJs8HD2QGMhukf3JdWefpfGOy2Heo,8743
6
+ private_attribute_cpp-1.2.7.dist-info/WHEEL,sha256=upREhtpl9tZ4GM5wmW6D_kM-MNmBcrXMNkyzURppwk0,113
7
+ private_attribute_cpp-1.2.7.dist-info/top_level.txt,sha256=vOfJKfFO3AgjCIvyK6ppYDBTyJSsEAkf5w34knGZ3JE,19
8
+ private_attribute_cpp-1.2.7.dist-info/RECORD,,
9
+ private_attribute_cpp-1.2.7.dist-info/sboms/auditwheel.cdx.json,sha256=7_f3dp_zFHbS1OerP_mpBT7q99W0FgDIfIzk3AhUMW4,1846
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.1)
3
3
  Root-Is-Purelib: false
4
4
  Tag: cp313-cp313-musllinux_1_2_x86_64
5
5
 
@@ -0,0 +1 @@
1
+ {"bomFormat": "CycloneDX", "specVersion": "1.4", "version": 1, "metadata": {"component": {"type": "library", "bom-ref": "pkg:pypi/private_attribute_cpp@1.2.7?file_name=private_attribute_cpp-1.2.7-cp313-cp313-musllinux_1_2_x86_64.whl", "name": "private_attribute_cpp", "version": "1.2.7", "purl": "pkg:pypi/private_attribute_cpp@1.2.7?file_name=private_attribute_cpp-1.2.7-cp313-cp313-musllinux_1_2_x86_64.whl"}, "tools": [{"name": "auditwheel", "version": "6.6.0"}]}, "components": [{"type": "library", "bom-ref": "pkg:pypi/private_attribute_cpp@1.2.7?file_name=private_attribute_cpp-1.2.7-cp313-cp313-musllinux_1_2_x86_64.whl", "name": "private_attribute_cpp", "version": "1.2.7", "purl": "pkg:pypi/private_attribute_cpp@1.2.7?file_name=private_attribute_cpp-1.2.7-cp313-cp313-musllinux_1_2_x86_64.whl"}, {"type": "library", "bom-ref": "pkg:apk/alpine/libstdc%2B%2B@14.2.0-r6#76f023cbc3d7b369d6008f354e88aa983d13e4bd8f06e4e49a01686039fe1509", "name": "libstdc++", "version": "14.2.0-r6", "purl": "pkg:apk/alpine/libstdc%2B%2B@14.2.0-r6"}, {"type": "library", "bom-ref": "pkg:apk/alpine/libgcc@14.2.0-r6#933a623c9e323e83b1734e630a342f206999adc096732a3fea9896fa0181ea29", "name": "libgcc", "version": "14.2.0-r6", "purl": "pkg:apk/alpine/libgcc@14.2.0-r6"}], "dependencies": [{"ref": "pkg:pypi/private_attribute_cpp@1.2.7?file_name=private_attribute_cpp-1.2.7-cp313-cp313-musllinux_1_2_x86_64.whl", "dependsOn": ["pkg:apk/alpine/libstdc%2B%2B@14.2.0-r6#76f023cbc3d7b369d6008f354e88aa983d13e4bd8f06e4e49a01686039fe1509", "pkg:apk/alpine/libgcc@14.2.0-r6#933a623c9e323e83b1734e630a342f206999adc096732a3fea9896fa0181ea29"]}, {"ref": "pkg:apk/alpine/libstdc%2B%2B@14.2.0-r6#76f023cbc3d7b369d6008f354e88aa983d13e4bd8f06e4e49a01686039fe1509"}, {"ref": "pkg:apk/alpine/libgcc@14.2.0-r6#933a623c9e323e83b1734e630a342f206999adc096732a3fea9896fa0181ea29"}]}
@@ -1,9 +0,0 @@
1
- private_attribute.cpython-313-x86_64-linux-musl.so,sha256=zb9wjpa79RCQDSjSo8SWLzPijqb4lvVmUgTUprMZwc4,3552609
2
- private_attribute.pyi,sha256=c3MbVJ2DcDxU_8YgLHRAmfgdV3iPp_1_TlsevD2gSn4,684
3
- private_attribute_cpp.libs/libgcc_s-0cd532bd.so.1,sha256=yPk0-VjyKzucjnkP3mvC0vVaua6Ln17qZUJbICcXgtA,181737
4
- private_attribute_cpp.libs/libstdc++-5d72f927.so.6.0.33,sha256=fogxHsmB1_D6C-a_-uHh8Ei_6Qh52a8vLlicJRM3ehk,3562401
5
- private_attribute_cpp-1.0.1.dist-info/METADATA,sha256=4vxi7T2pMv-pYfnJ5l7TNMMr2FQo4WB1CY5xxyStnJg,7761
6
- private_attribute_cpp-1.0.1.dist-info/WHEEL,sha256=4VbEOkf4fdBUBHdV24POjoH-zuik_eIDLSImZZCAQpQ,112
7
- private_attribute_cpp-1.0.1.dist-info/top_level.txt,sha256=vOfJKfFO3AgjCIvyK6ppYDBTyJSsEAkf5w34knGZ3JE,19
8
- private_attribute_cpp-1.0.1.dist-info/RECORD,,
9
- private_attribute_cpp-1.0.1.dist-info/sboms/auditwheel.cdx.json,sha256=PhWUG4uPn6PPUChTKwZwRP3zIuQhwBb8EqP3fUGKNtc,1846
@@ -1 +0,0 @@
1
- {"bomFormat": "CycloneDX", "specVersion": "1.4", "version": 1, "metadata": {"component": {"type": "library", "bom-ref": "pkg:pypi/private_attribute_cpp@1.0.1?file_name=private_attribute_cpp-1.0.1-cp313-cp313-musllinux_1_2_x86_64.whl", "name": "private_attribute_cpp", "version": "1.0.1", "purl": "pkg:pypi/private_attribute_cpp@1.0.1?file_name=private_attribute_cpp-1.0.1-cp313-cp313-musllinux_1_2_x86_64.whl"}, "tools": [{"name": "auditwheel", "version": "6.5.0"}]}, "components": [{"type": "library", "bom-ref": "pkg:pypi/private_attribute_cpp@1.0.1?file_name=private_attribute_cpp-1.0.1-cp313-cp313-musllinux_1_2_x86_64.whl", "name": "private_attribute_cpp", "version": "1.0.1", "purl": "pkg:pypi/private_attribute_cpp@1.0.1?file_name=private_attribute_cpp-1.0.1-cp313-cp313-musllinux_1_2_x86_64.whl"}, {"type": "library", "bom-ref": "pkg:apk/alpine/libgcc@14.2.0-r6#933a623c9e323e83b1734e630a342f206999adc096732a3fea9896fa0181ea29", "name": "libgcc", "version": "14.2.0-r6", "purl": "pkg:apk/alpine/libgcc@14.2.0-r6"}, {"type": "library", "bom-ref": "pkg:apk/alpine/libstdc%2B%2B@14.2.0-r6#76f023cbc3d7b369d6008f354e88aa983d13e4bd8f06e4e49a01686039fe1509", "name": "libstdc++", "version": "14.2.0-r6", "purl": "pkg:apk/alpine/libstdc%2B%2B@14.2.0-r6"}], "dependencies": [{"ref": "pkg:pypi/private_attribute_cpp@1.0.1?file_name=private_attribute_cpp-1.0.1-cp313-cp313-musllinux_1_2_x86_64.whl", "dependsOn": ["pkg:apk/alpine/libgcc@14.2.0-r6#933a623c9e323e83b1734e630a342f206999adc096732a3fea9896fa0181ea29", "pkg:apk/alpine/libstdc%2B%2B@14.2.0-r6#76f023cbc3d7b369d6008f354e88aa983d13e4bd8f06e4e49a01686039fe1509"]}, {"ref": "pkg:apk/alpine/libgcc@14.2.0-r6#933a623c9e323e83b1734e630a342f206999adc096732a3fea9896fa0181ea29"}, {"ref": "pkg:apk/alpine/libstdc%2B%2B@14.2.0-r6#76f023cbc3d7b369d6008f354e88aa983d13e4bd8f06e4e49a01686039fe1509"}]}