Skip to main content

Immutable constant types for Python.

Project description

sconst

Immutable constant types for Python.

Installation

pip install sconst

Usage

Constant types

from sconst import IntConstant, StrConstant, ListConstant, TupleConstant

x = IntConstant(42)
print(x.value)   # 42
x.value = 10     # raises ChangeConstError

s = StrConstant("hello")
print("ell" in s)  # True
s + " world"       # raises ChangeConstError

items = ListConstant([1, 2, 3])
print(items[0])    # 1
for item in items: # iteration works
    print(item)

coords = TupleConstant((10, 20))
print(len(coords)) # 2

const_property descriptor

A read-only property whose value is computed once and then frozen:

from sconst import const_property

class Config:
    @const_property
    def max_retries(self):
        return 5

cfg = Config()
cfg.max_retries        # 5
cfg.max_retries = 10   # raises ChangeConstError
del cfg.max_retries    # raises DeleteConstError

Classes

Class Description
BaseConstant Base class for all constant wrappers
IntConstant Constant integer — blocks arithmetic and mutation
StrConstant Constant string — blocks +, *, and item assignment
IterableConstant Base for iterable constants — supports iteration, indexing, len(), and in
ListConstant Constant list
TupleConstant Constant tuple

Exceptions

Exception Raised when
SconstException Base exception for all sconst errors
ChangeConstError An attempt is made to modify a constant
DeleteConstError An attempt is made to delete a constant attribute

License

MIT

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

sconst-1.0.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

sconst-1.0.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file sconst-1.0.0.tar.gz.

File metadata

  • Download URL: sconst-1.0.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for sconst-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6c25520a725a22458826a201b3cba15b3e0474ca6415203a422f800500ac9828
MD5 087ffa7123beea681bfab03218767ea3
BLAKE2b-256 6cf8322eeae3535c9e9bec268eb485670f4983bbe15238ada93c2cf039e40b0d

See more details on using hashes here.

File details

Details for the file sconst-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sconst-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for sconst-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5a0d672114980b5a4291cd14d4d46f62dae68e247c7502636f28a20679cd98f
MD5 81a001b66d4222ed22aabc94980a9a5c
BLAKE2b-256 5a854723736c08054de8b0e41a0352cd010c95c6a6cb73d66029052f59be15c2

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