Skip to main content

constattr

test License Maintenance made-with-python PyPI pyversions PyPI version constattr PyPI status PyPI download month Maintainability 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

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)

Source distribution for constattr 0.0.8
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

Release history Release notifications | RSS feed

This release

0.0.8 This release

1 release file

0.0.7

1 release file

0.0.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page