Skip to main content

Enforce that your constant class attributes are not re-assigned

Project description

constattr

test License Maintenance made-with-python 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.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


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.4.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

constattr-0.0.4-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for constattr-0.0.4.tar.gz
Algorithm Hash digest
SHA256 eb7f034a8b2782cf94b9e5b37cd0be67499cafbd99c983a856b6b9d02c456e3c
MD5 0bcf9f98ff1c25af32c6670ae8e0e920
BLAKE2b-256 04c6cac98e3e4031c0e621402b3939d75b4e8eecb56bf879bf9812818f675321

See more details on using hashes here.

File details

Details for the file constattr-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: constattr-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.4

File hashes

Hashes for constattr-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 87f66bce964abe5ef3ea7e294bc19f4ddebc911faaab1292701f67b824551dcd
MD5 64b12c5f24abfb6e3a94d104fabc914f
BLAKE2b-256 a12a99abdaeb1e23653ac5444cde8d8ebf9c3c74c01b2072128bd8fe4af0bbde

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