private-attribute-cpp 1.0.11__cp314-cp314t-win32.whl → 1.2.4__cp314-cp314t-win32.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.
Potentially problematic release.
This version of private-attribute-cpp might be problematic. Click here for more details.
- private_attribute.cp314t-win32.pyd +0 -0
- private_attribute.pyi +15 -0
- {private_attribute_cpp-1.0.11.dist-info → private_attribute_cpp-1.2.4.dist-info}/METADATA +66 -11
- private_attribute_cpp-1.2.4.dist-info/RECORD +6 -0
- {private_attribute_cpp-1.0.11.dist-info → private_attribute_cpp-1.2.4.dist-info}/WHEEL +1 -1
- private_attribute_cpp-1.0.11.dist-info/RECORD +0 -6
- {private_attribute_cpp-1.0.11.dist-info → private_attribute_cpp-1.2.4.dist-info}/top_level.txt +0 -0
|
Binary file
|
private_attribute.pyi
CHANGED
|
@@ -20,3 +20,18 @@ class PrivateAttrType(type):
|
|
|
20
20
|
class PrivateAttrBase(metaclass=PrivateAttrType):
|
|
21
21
|
__slots__ = ()
|
|
22
22
|
__private_attrs__ = ()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class private_temp:
|
|
26
|
+
@property
|
|
27
|
+
def name(self) -> str: ...
|
|
28
|
+
@property
|
|
29
|
+
def bases(self) -> tuple[type]: ...
|
|
30
|
+
@property
|
|
31
|
+
def attrs(self) -> dict[str, Any]: ...
|
|
32
|
+
@property
|
|
33
|
+
def kwds(self) -> dict[str, Any]: ...
|
|
34
|
+
|
|
35
|
+
def prepare(name: str, bases: tuple, attrs: PrivateAttrDict, **kwds) -> private_temp: ...
|
|
36
|
+
def postprocess(typ: type, temp: private_temp) -> None: ...
|
|
37
|
+
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.
|
|
3
|
+
Version: 1.2.4
|
|
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
|
|
@@ -68,11 +68,11 @@ print(obj.expensive_api_call(10)) # works with all decorators applied
|
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
| # | API | Purpose | Required? |
|
|
71
|
-
|
|
71
|
+
| --- | ---------------------------------------- | ------------------------------------------------------- | ----------- |
|
|
72
72
|
| 1 | PrivateAttrBase | Base class – must inherit | Yes |
|
|
73
|
-
| 1 | PrivateWrapProxy
|
|
74
|
-
| 2 | private_func=callable
|
|
75
|
-
| 3 | Pass private_func in class definition | Same as above
|
|
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 |
|
|
76
76
|
| 4 | \_\_private_attrs\_\_ list | Declare which attributes are private | Yes |
|
|
77
77
|
| 5 | @PrivateWrapProxy(...) | Make any decorator compatible with private attributes | When needed |
|
|
78
78
|
| 6 | method.result.xxx chain + dummy wrap | Fix decorator order and name conflicts | When needed |
|
|
@@ -138,8 +138,7 @@ class MyClass(PrivateAttrBase):
|
|
|
138
138
|
def method1(self):
|
|
139
139
|
...
|
|
140
140
|
|
|
141
|
-
@method1.attr_name
|
|
142
|
-
@PrivateWrapProxy(lambda _: _) # use empty function to wrap
|
|
141
|
+
@PrivateWrapProxy(method1.attr_name, method1) # Use the argument "method1" to save old func
|
|
143
142
|
def method1(self):
|
|
144
143
|
...
|
|
145
144
|
|
|
@@ -147,8 +146,7 @@ class MyClass(PrivateAttrBase):
|
|
|
147
146
|
def method2(self):
|
|
148
147
|
...
|
|
149
148
|
|
|
150
|
-
@method2.attr_name
|
|
151
|
-
@PrivateWrapProxy(lambda _: _)
|
|
149
|
+
@PrivateWrapProxy(method2.attr_name, method2) # Use the argument "method2" to save old func
|
|
152
150
|
def method2(self):
|
|
153
151
|
...
|
|
154
152
|
|
|
@@ -181,6 +179,63 @@ class MyClass(PrivateAttrBase):
|
|
|
181
179
|
def method2(self):
|
|
182
180
|
```
|
|
183
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.base, 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
|
+
|
|
184
239
|
## Notes
|
|
185
240
|
|
|
186
241
|
- All of the private attributes class must contain the `__private_attrs__` attribute.
|
|
@@ -199,7 +254,7 @@ MIT
|
|
|
199
254
|
|
|
200
255
|
## Requirement
|
|
201
256
|
|
|
202
|
-
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.
|
|
203
258
|
|
|
204
259
|
## Support
|
|
205
260
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
private_attribute.cp314t-win32.pyd,sha256=ijvAzoiikfzrCJCynxjdz_LEhg67RErs9I-SFY01-Yk,147968
|
|
2
|
+
private_attribute.pyi,sha256=R4rCgSPyIhOT28ewAeCmuWbaMO3uhaEATpBL8P-h7Uw,1251
|
|
3
|
+
private_attribute_cpp-1.2.4.dist-info/METADATA,sha256=9vpCc7jFgzMcTmpG9yM0XJKdWO7QbiZMKj1QJKagLBk,8939
|
|
4
|
+
private_attribute_cpp-1.2.4.dist-info/WHEEL,sha256=_oANSYd4_nQB_UF_JOhTk-kt5AphIxnRYMKIVCyNu0w,99
|
|
5
|
+
private_attribute_cpp-1.2.4.dist-info/top_level.txt,sha256=vOfJKfFO3AgjCIvyK6ppYDBTyJSsEAkf5w34knGZ3JE,19
|
|
6
|
+
private_attribute_cpp-1.2.4.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
private_attribute.cp314t-win32.pyd,sha256=LlBEvfaWycsz1YvFNXWLU2LZI-777dizHGELqRBBuI4,139776
|
|
2
|
-
private_attribute.pyi,sha256=pWpoUdy38dA12n8wyE-knOtoQAd7ENj-f14pxwyHijQ,804
|
|
3
|
-
private_attribute_cpp-1.0.11.dist-info/METADATA,sha256=p5pL0jWFT-3Z7R88-d6sALWz8Flh23AjGCJv3FvbdLc,7410
|
|
4
|
-
private_attribute_cpp-1.0.11.dist-info/WHEEL,sha256=QZj5mezaA5oNm6LDNW4xgYLgBYwS1DTKsN1RAjQk9mo,98
|
|
5
|
-
private_attribute_cpp-1.0.11.dist-info/top_level.txt,sha256=vOfJKfFO3AgjCIvyK6ppYDBTyJSsEAkf5w34knGZ3JE,19
|
|
6
|
-
private_attribute_cpp-1.0.11.dist-info/RECORD,,
|
{private_attribute_cpp-1.0.11.dist-info → private_attribute_cpp-1.2.4.dist-info}/top_level.txt
RENAMED
|
File without changes
|