private-attribute-cpp 3.0.1__tar.gz → 3.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-3.0.1 → private_attribute_cpp-3.0.3}/PKG-INFO +36 -19
  2. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/README.md +35 -18
  3. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/private_attribute.cpp +1131 -189
  4. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/private_attribute.pyi +68 -74
  5. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/pyproject.toml +1 -1
  6. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_private_abc.py +6 -7
  7. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/CMakeLists.txt +0 -0
  8. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/LICENSE +0 -0
  9. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/picosha2.h +0 -0
  10. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_attr_classify_owner.py +0 -0
  11. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_class_private_attrs.py +0 -0
  12. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_gc_collect.py +0 -0
  13. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_init_subclass.py +0 -0
  14. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_private_attrs.py +0 -0
  15. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_private_func.py +0 -0
  16. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_private_inheritance.py +0 -0
  17. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_private_method.py +0 -0
  18. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_private_super.py +0 -0
  19. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_private_wrap.py +0 -0
  20. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_slots_cycle.py +0 -0
  21. {private_attribute_cpp-3.0.1 → private_attribute_cpp-3.0.3}/tests/test_use_parents.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: private_attribute_cpp
3
- Version: 3.0.1
3
+ Version: 3.0.3
4
4
  Summary: A Python package that provides a way to define private attributes in C++ implementation.
5
5
  Author-Email: HuangHaoHua <13140752715@example.com>
6
6
  License-Expression: MIT
@@ -327,9 +327,9 @@ private attributes only** — it is not for instance-attribute cross-type access
327
327
  | `_PrivateWrap` | class | Returned by `PrivateWrapProxy`; exposes `.result` and `.funcs`. |
328
328
  | `PrivateSuper(A, B, C, obj)` | class | Read a parent class's class-level private attribute defined for another class; calls `__get__(obj, A)`. |
329
329
  | `PrivateClassSuper(A, B, C, cls)` | class | Classmethod flavour of `PrivateSuper`; calls `__get__(None, cls)`. |
330
- | `prepare(name, bases, attrs, **kwds)` | function | Context manager for building private-attribute classes in a custom metaclass. |
331
- | `postprocess(typ, temp)` | function | Finalize a class created via `prepare`. |
332
- | `register_metaclass(metaclass)` | function | Register a custom metaclass so it can produce private-attribute classes. |
330
+ | `create_new(func=None)` | function | Register and control a custom metaclass automatically; placed in the metaclass body (or used as a decorator). |
331
+ | `create_meta_slot(name)` | function | Create the final slot (e.g. `__setattr__`) for a registered metaclass; empty slot or decorator. |
332
+ | `create_slot(name)` | function | Create the final slot for a private-attribute class; empty slot or decorator. |
333
333
  | `ensure_type(typ)` | function | Re-inject the special-method slot descriptors and `tp_traverse`/`tp_clear` wrappers on a type. |
334
334
  | `ensure_metaclass(metaclass)` | function | Re-inject the corresponding slot descriptors and wrappers on a metaclass. |
335
335
 
@@ -345,21 +345,16 @@ Class-definition options:
345
345
 
346
346
  ## Custom metaclasses
347
347
 
348
- To combine private attributes with another metaclass (e.g. `ABCMeta`), use the
349
- `prepare` / `postprocess` pair and register the metaclass:
348
+ To combine private attributes with another metaclass (e.g. `ABCMeta`), put a
349
+ `create_new` slot directly in the metaclass. `create_new` takes care of
350
+ registration and control automatically:
350
351
 
351
352
  ```python
352
353
  from abc import ABCMeta, abstractmethod
353
354
  import private_attribute
354
355
 
355
356
  class PrivateAbcMeta(ABCMeta):
356
- def __new__(cls, name, bases, attrs, **kwargs):
357
- with private_attribute.prepare(name, bases, attrs, **kwargs) as temp:
358
- typ = super().__new__(cls, temp.name, temp.bases, temp.attrs, **temp.kwds)
359
- private_attribute.postprocess(typ, temp) # or temp.postprocess(typ)
360
- return typ
361
-
362
- private_attribute.register_metaclass(PrivateAbcMeta)
357
+ __new__ = private_attribute.create_new()
363
358
 
364
359
  class MyClass(metaclass=PrivateAbcMeta):
365
360
  __private_attrs__ = ("_a",)
@@ -381,10 +376,31 @@ a._a # AttributeError: private attribute
381
376
  MyClass() # TypeError: Can't instantiate abstract class ...
382
377
  ```
383
378
 
384
- `prepare(...)` returns a temporary object exposing `.name`, `.bases`, `.attrs`,
385
- and `.kwds` (and, since v2.1.17, a `.postprocess(typ)` shortcut). Since v2.2.3
386
- it is a context manager (`with`), which guarantees the internal creation lock is
387
- released even if construction fails.
379
+ `create_new` also works as a decorator:
380
+
381
+ ```python
382
+ class PrivateAbcMeta(ABCMeta):
383
+ @private_attribute.create_new
384
+ def __new__(cls, name, bases, attrs, **kwargs):
385
+ return super().__new__(cls, name, bases, attrs, **kwargs)
386
+ ```
387
+
388
+ Custom special-method slots on the metaclass use `create_meta_slot`, and on a
389
+ private-attribute class use `create_slot`. Both take the slot name first and
390
+ work either as an empty slot or as a decorator:
391
+
392
+ ```python
393
+ class PrivateAbcMeta(ABCMeta):
394
+ __new__ = private_attribute.create_new()
395
+ __setattr__ = private_attribute.create_meta_slot("__setattr__")()
396
+
397
+ class MyClass(private_attribute.PrivateAttrBase):
398
+ __setattr__ = private_attribute.create_slot("__setattr__")()
399
+ ```
400
+
401
+ > The old `prepare` / `postprocess` pair and `register_metaclass` are
402
+ > deprecated (they emit a warning) and kept only for backward compatibility;
403
+ > new code should use `create_new`.
388
404
 
389
405
  ---
390
406
 
@@ -414,9 +430,9 @@ released even if construction fails.
414
430
  `__private_attrs__` or opts in with `use_parents=True`.
415
431
  - **v2.2.1** — `prepare` locks private-attribute-type creation so only one type
416
432
  is being built (`type.__new__`) at a time; `postprocess` unlocks it. The lock
417
- is released automatically on failure.
433
+ is released automatically on failure. (Deprecated; see `create_new`.)
418
434
  - **v2.2.3** — prefer the `with` form of `prepare`/`postprocess` to guarantee
419
- the lock is released.
435
+ the lock is released. (Deprecated; see `create_new`.)
420
436
  - CPython may reset the special-method slot descriptors (e.g. when you assign
421
437
  `__getattribute__` / `__setattr__`). Use `ensure_type` (or
422
438
  `ensure_metaclass`) to re-inject them, and avoid setting those methods on
@@ -430,6 +446,7 @@ released even if construction fails.
430
446
  straight to the user callback without re-classification. Registered types and
431
447
  created types must be heap types (static types are rejected).
432
448
  - `register_metaclass` requires a metaclass that supports weak references.
449
+ (Deprecated; use `create_new`, which registers the metaclass automatically.)
433
450
  - Do **not** set `__static_attributes__` on a private-attribute class; it is
434
451
  removed automatically.
435
452
 
@@ -317,9 +317,9 @@ private attributes only** — it is not for instance-attribute cross-type access
317
317
  | `_PrivateWrap` | class | Returned by `PrivateWrapProxy`; exposes `.result` and `.funcs`. |
318
318
  | `PrivateSuper(A, B, C, obj)` | class | Read a parent class's class-level private attribute defined for another class; calls `__get__(obj, A)`. |
319
319
  | `PrivateClassSuper(A, B, C, cls)` | class | Classmethod flavour of `PrivateSuper`; calls `__get__(None, cls)`. |
320
- | `prepare(name, bases, attrs, **kwds)` | function | Context manager for building private-attribute classes in a custom metaclass. |
321
- | `postprocess(typ, temp)` | function | Finalize a class created via `prepare`. |
322
- | `register_metaclass(metaclass)` | function | Register a custom metaclass so it can produce private-attribute classes. |
320
+ | `create_new(func=None)` | function | Register and control a custom metaclass automatically; placed in the metaclass body (or used as a decorator). |
321
+ | `create_meta_slot(name)` | function | Create the final slot (e.g. `__setattr__`) for a registered metaclass; empty slot or decorator. |
322
+ | `create_slot(name)` | function | Create the final slot for a private-attribute class; empty slot or decorator. |
323
323
  | `ensure_type(typ)` | function | Re-inject the special-method slot descriptors and `tp_traverse`/`tp_clear` wrappers on a type. |
324
324
  | `ensure_metaclass(metaclass)` | function | Re-inject the corresponding slot descriptors and wrappers on a metaclass. |
325
325
 
@@ -335,21 +335,16 @@ Class-definition options:
335
335
 
336
336
  ## Custom metaclasses
337
337
 
338
- To combine private attributes with another metaclass (e.g. `ABCMeta`), use the
339
- `prepare` / `postprocess` pair and register the metaclass:
338
+ To combine private attributes with another metaclass (e.g. `ABCMeta`), put a
339
+ `create_new` slot directly in the metaclass. `create_new` takes care of
340
+ registration and control automatically:
340
341
 
341
342
  ```python
342
343
  from abc import ABCMeta, abstractmethod
343
344
  import private_attribute
344
345
 
345
346
  class PrivateAbcMeta(ABCMeta):
346
- def __new__(cls, name, bases, attrs, **kwargs):
347
- with private_attribute.prepare(name, bases, attrs, **kwargs) as temp:
348
- typ = super().__new__(cls, temp.name, temp.bases, temp.attrs, **temp.kwds)
349
- private_attribute.postprocess(typ, temp) # or temp.postprocess(typ)
350
- return typ
351
-
352
- private_attribute.register_metaclass(PrivateAbcMeta)
347
+ __new__ = private_attribute.create_new()
353
348
 
354
349
  class MyClass(metaclass=PrivateAbcMeta):
355
350
  __private_attrs__ = ("_a",)
@@ -371,10 +366,31 @@ a._a # AttributeError: private attribute
371
366
  MyClass() # TypeError: Can't instantiate abstract class ...
372
367
  ```
373
368
 
374
- `prepare(...)` returns a temporary object exposing `.name`, `.bases`, `.attrs`,
375
- and `.kwds` (and, since v2.1.17, a `.postprocess(typ)` shortcut). Since v2.2.3
376
- it is a context manager (`with`), which guarantees the internal creation lock is
377
- released even if construction fails.
369
+ `create_new` also works as a decorator:
370
+
371
+ ```python
372
+ class PrivateAbcMeta(ABCMeta):
373
+ @private_attribute.create_new
374
+ def __new__(cls, name, bases, attrs, **kwargs):
375
+ return super().__new__(cls, name, bases, attrs, **kwargs)
376
+ ```
377
+
378
+ Custom special-method slots on the metaclass use `create_meta_slot`, and on a
379
+ private-attribute class use `create_slot`. Both take the slot name first and
380
+ work either as an empty slot or as a decorator:
381
+
382
+ ```python
383
+ class PrivateAbcMeta(ABCMeta):
384
+ __new__ = private_attribute.create_new()
385
+ __setattr__ = private_attribute.create_meta_slot("__setattr__")()
386
+
387
+ class MyClass(private_attribute.PrivateAttrBase):
388
+ __setattr__ = private_attribute.create_slot("__setattr__")()
389
+ ```
390
+
391
+ > The old `prepare` / `postprocess` pair and `register_metaclass` are
392
+ > deprecated (they emit a warning) and kept only for backward compatibility;
393
+ > new code should use `create_new`.
378
394
 
379
395
  ---
380
396
 
@@ -404,9 +420,9 @@ released even if construction fails.
404
420
  `__private_attrs__` or opts in with `use_parents=True`.
405
421
  - **v2.2.1** — `prepare` locks private-attribute-type creation so only one type
406
422
  is being built (`type.__new__`) at a time; `postprocess` unlocks it. The lock
407
- is released automatically on failure.
423
+ is released automatically on failure. (Deprecated; see `create_new`.)
408
424
  - **v2.2.3** — prefer the `with` form of `prepare`/`postprocess` to guarantee
409
- the lock is released.
425
+ the lock is released. (Deprecated; see `create_new`.)
410
426
  - CPython may reset the special-method slot descriptors (e.g. when you assign
411
427
  `__getattribute__` / `__setattr__`). Use `ensure_type` (or
412
428
  `ensure_metaclass`) to re-inject them, and avoid setting those methods on
@@ -420,6 +436,7 @@ released even if construction fails.
420
436
  straight to the user callback without re-classification. Registered types and
421
437
  created types must be heap types (static types are rejected).
422
438
  - `register_metaclass` requires a metaclass that supports weak references.
439
+ (Deprecated; use `create_new`, which registers the metaclass automatically.)
423
440
  - Do **not** set `__static_attributes__` on a private-attribute class; it is
424
441
  removed automatically.
425
442