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 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.
Metadata
Release files for constattr 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| constattr-0.0.8.tar.gz | 4.2 kB | Details |
Release files / constattr-0.0.8.tar.gz
| Download URL | constattr-0.0.8.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b9350b6d34c4f64d5bd4d265dc537ec46137cb691643e0a0de6369a4f59d6c2
|
|
BLAKE2b-256 checksum How to use checksums |
689fe51a1ed8f0e41fd5b35ca8a73def0b85d2e80c655d03ce1dc6622ebdf127
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|