Skip to main content

Semimutable

Tests codecov

A dataclass drop-in that allows you to define individual fields as immutable.

Usage

Simply replace all your dataclasses imports with semimutable, and use field(frozen=True) for the fields you want to be immutable.

field takes in the same parameters as dataclasses.field, with an extra frozen boolean flag that defaults to False. You can specify default values, default factories, and other options just like you would with a regular dataclass field.

Here is one example from our tests.

from semimutable import dataclass, field

@dataclass
class Simple:
    x: int = field(frozen=True)
    y: int = 0 # normal, mutable field

def test_frozen_field_is_immutable():
    obj = Simple(x=1, y=2)
    with pytest.raises(TypeError):
        obj.x = 99

def test_non_frozen_field_is_mutable():
    obj = Simple(x=1, y=2)
    obj.y = 42
    assert obj.y == 42

Credits

Parts of this library are derived from Python's standard library dataclasses module. The original implementation is distributed under the Python Software Foundation License. See LICENSE.PSF for the full license text.

Release files for semimutable 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for semimutable 0.1.0
File Size Uploaded
semimutable-0.1.0.tar.gz 43.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for semimutable 0.1.0
File Interpreter ABI Platform
semimutable-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 52.3 kB

Release files / semimutable-0.1.0.tar.gz

Download URL semimutable-0.1.0.tar.gz
Size 43.9 kB
Tags Source
SHA-256 checksum
How to use checksums
37e35ac442d103c367c87e1e219ef1afcc366729319a990324363ddb718cf31c
BLAKE2b-256 checksum
How to use checksums
ab007ce6af378095896fa39feeeeb22a3f5c4e5ed11051000f3803541c4a6945
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.12

Release files / semimutable-0.1.0-py3-none-any.whl

Download URL semimutable-0.1.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38b253ca963c74d2c1b2d5ebe2cce10a87ff621d22d842eb4b5444a418bb4c43
BLAKE2b-256 checksum
How to use checksums
0245abc6f3606444f362d43a37a8c6cd8ac6af9b810b96507ed3f473e3d84359
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.12

Release history Release notifications | RSS feed

This release

0.1.0 This release

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