Constant Properties Protector Package
With the help of this module, you can protect some of the properties in a class. Protecting means avoiding to change them but keep them publicly available.
from constant_properties_protector import CPP
class A:
def __init__(self):
CPP.protect(self, 'initialized_protected')
CPP.protect(self, 'uninitialized_protected')
self._initialized_protected = 12
a = A()
print(a.initialized_protected)
# >>> 12
a.t = 2
print(a.t)
# >>> 2
a.initialized_protected += 1
# Exception: Can not modify constant property: initialized_protected
a.uninitialized_protected = 10
# Exception: Can not modify constant property: uninitialized_protected
class B(A):
def __init__(self):
super().__init__()
CPP.protect(self, 'new_protected_value')
self._new_protected_value = 26
b = B()
print(b.new_protected_value)
# >>> 26
b.new_protected_value += 2
# Exception: Can not modify constant property: new_protected_value
NOTE:
- There is no need to inherit from CPP.
- Use
_first of the protected property name to get full access to it. - Use
protectfunction to add to protected properties. - CPP will define python properties for your class. So it affects the class, not the instance. DON'T use CPP to protect property in runtime. Use it to define protected values for all instances of a class.
Installation
pip install constant-properties-protector
Metadata
Release files for constant-properties-protector 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| constant-properties-protector-0.2.2.tar.gz | 2.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| constant_properties_protector-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.4 kB
Release files / constant-properties-protector-0.2.2.tar.gz
| Download URL | constant-properties-protector-0.2.2.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3017daffe2215ad19926f833172e26774144b6fd1a5431aa571098e05dfeb316
|
|
BLAKE2b-256 checksum How to use checksums |
709063e0c22203c7d0a6eec80220e304158e24aefc7286fb264edfeed114ca57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|
Release files / constant_properties_protector-0.2.2-py3-none-any.whl
| Download URL | constant_properties_protector-0.2.2-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fcc3c89ecddce1584e43956e63ae5068933a1dda3317b4cf7489df8d0c12cffb
|
|
BLAKE2b-256 checksum How to use checksums |
6534e54c77c96bd754e301f8340b69f68f2f15be1c9eed1dbe865be07948b566
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|