Enforce that your constant class attributes are not re-assigned
Project description
constattr
Enforce your class constants in python.
The only constant in life is change
Heraclitus
Not anymore!
Didacus I. Granatensis
Usage
Decorate your class with constclassattrs and when a class attribute that is uppercase
is re-assigned the exception ConstantAssignmentError will be raised.
Example
from constattr.decorators import constclassattrs
@constclassattrs
class Example1:
MY_CONST1 = '1'
MY_CONST2 = '2'
# This will raise the ConstAssignmentError exception
Example1.MY_CONST1 = 'new value for the constant'
Limitations
If your class has a metaclass defined, it will work, but in case of conflict the MRO in the metaclass will choose the ConstantEnforcerMeta class first.
Dependencies
This package has no dependencies.
License
MIT license, but if you need any other contact me.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file constattr-0.0.7.tar.gz.
File metadata
- Download URL: constattr-0.0.7.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a794570e35a2d3c4c32a840ab9744d56cb871e9ba9411158e2fd6a2ae16bfdd
|
|
| MD5 |
b4607a08b237c0331e6e67ad09c9c97e
|
|
| BLAKE2b-256 |
0e906611090181fd659db1868e7179330c4808b1b04fed3399ec211e68d0fd7a
|