Skip to main content

Enforce that your constant class attributes are not re-assigned

Project description

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.

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

constattr-0.0.8.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file constattr-0.0.8.tar.gz.

File metadata

  • Download URL: constattr-0.0.8.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for constattr-0.0.8.tar.gz
Algorithm Hash digest
SHA256 8b9350b6d34c4f64d5bd4d265dc537ec46137cb691643e0a0de6369a4f59d6c2
MD5 a281a1501c4d97369d2d959ae1dff22e
BLAKE2b-256 689fe51a1ed8f0e41fd5b35ca8a73def0b85d2e80c655d03ce1dc6622ebdf127

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page