No project description provided
Project description
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
protect
function 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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file constant-properties-protector-0.2.2.tar.gz
.
File metadata
- Download URL: constant-properties-protector-0.2.2.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3017daffe2215ad19926f833172e26774144b6fd1a5431aa571098e05dfeb316 |
|
MD5 | 0c0eed0a44c3c9448994579adbedb8f6 |
|
BLAKE2b-256 | 709063e0c22203c7d0a6eec80220e304158e24aefc7286fb264edfeed114ca57 |
File details
Details for the file constant_properties_protector-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: constant_properties_protector-0.2.2-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcc3c89ecddce1584e43956e63ae5068933a1dda3317b4cf7489df8d0c12cffb |
|
MD5 | 70a7e03ea9543483d190ed8520622c78 |
|
BLAKE2b-256 | 6534e54c77c96bd754e301f8340b69f68f2f15be1c9eed1dbe865be07948b566 |