https://github.com/diegojromerolopez/constattr
Enforce your const class attributes in python
https://github.com/diegojromerolopez/constattr
class-attributes const constant python
Last synced: 4 months ago
JSON representation
Enforce your const class attributes in python
- Host: GitHub
- URL: https://github.com/diegojromerolopez/constattr
- Owner: diegojromerolopez
- License: mit
- Created: 2025-01-18T08:48:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-19T18:49:34.000Z (over 1 year ago)
- Last Synced: 2025-02-19T21:48:23.548Z (over 1 year ago)
- Topics: class-attributes, const, constant, python
- Language: Python
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# constattr

[](https://opensource.org/licenses/MIT)
[](https://github.com/diegojromerolopez/constattr/graphs/commit-activity)
[](https://www.python.org/)
[](https://pypi.python.org/pypi/constattr/)
[](https://pypi.python.org/pypi/constattr/)
[](https://pypi.python.org/pypi/constattr/)
[](https://pypi.python.org/pypi/constattr/)
[](https://codeclimate.com/github/diegojromerolopez/constattr/maintainability)
[](https://codeclimate.com/github/diegojromerolopez/constattr/test_coverage)
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
```python
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](/constattr/const_enforcer_meta.py)
class first.
## Dependencies
This package has no dependencies.
## License
[MIT](LICENSE) license, but if you need any other contact me.