Name | semimutable JSON |
Version |
0.1.0a0
JSON |
| download |
home_page | None |
Summary | Drop-in replacement for Python's built-in `dataclasses` module, allowing for certain fields to be mutable while others remain immutable. |
upload_time | 2025-07-21 05:13:30 |
maintainer | None |
docs_url | None |
author | Glinte |
requires_python | >=3.12 |
license | None |
keywords |
dataclasses
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Semimutable
A dataclass drop-in that allows you to define individual fields as immutable.
## Usage
Simply replace all your `dataclasses` imports with `semimutable`, and use `frozen_field` to replace `field` for the fields you want to be immutable.
`frozen_field` takes in the same parameters as `dataclasses.field`, so 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.
```python
from semimutable import dataclass, frozen_field
@dataclass
class Simple:
x: int = frozen_field()
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
```
Raw data
{
"_id": null,
"home_page": null,
"name": "semimutable",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "dataclasses",
"author": "Glinte",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/29/9e/91b70fb53c68e7f34e3c882c18340e5c30636a7700ab8fcb5eeed7da2a1f/semimutable-0.1.0a0.tar.gz",
"platform": null,
"description": "# Semimutable\n\nA dataclass drop-in that allows you to define individual fields as immutable.\n\n## Usage\n\nSimply replace all your `dataclasses` imports with `semimutable`, and use `frozen_field` to replace `field` for the fields you want to be immutable.\n\n`frozen_field` takes in the same parameters as `dataclasses.field`, so you can specify default values, default factories, and other options just like you would with a regular dataclass field.\n\nHere is one example from our tests.\n\n```python\nfrom semimutable import dataclass, frozen_field\n\n@dataclass\nclass Simple:\n x: int = frozen_field()\n y: int = 0 # normal, mutable field\n\ndef test_frozen_field_is_immutable():\n obj = Simple(x=1, y=2)\n with pytest.raises(TypeError):\n obj.x = 99\n\ndef test_non_frozen_field_is_mutable():\n obj = Simple(x=1, y=2)\n obj.y = 42\n assert obj.y == 42\n```",
"bugtrack_url": null,
"license": null,
"summary": "Drop-in replacement for Python's built-in `dataclasses` module, allowing for certain fields to be mutable while others remain immutable.",
"version": "0.1.0a0",
"project_urls": null,
"split_keywords": [
"dataclasses"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a401d6b1ed0a5dab6ccd7d7c8deedcc8e359a196af715b4ba63ef1462aadb372",
"md5": "d203352a8124eda4f7a5162060801d41",
"sha256": "da990fbe43b09398a161505ac7bccc6bec2875ee91b128f008335666e2685b0d"
},
"downloads": -1,
"filename": "semimutable-0.1.0a0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d203352a8124eda4f7a5162060801d41",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 7708,
"upload_time": "2025-07-21T05:13:29",
"upload_time_iso_8601": "2025-07-21T05:13:29.041128Z",
"url": "https://files.pythonhosted.org/packages/a4/01/d6b1ed0a5dab6ccd7d7c8deedcc8e359a196af715b4ba63ef1462aadb372/semimutable-0.1.0a0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "299e91b70fb53c68e7f34e3c882c18340e5c30636a7700ab8fcb5eeed7da2a1f",
"md5": "58dd6916253960e6fbec1e654c6729d4",
"sha256": "e603838aff73aff1232202540e349d8bdb91ab6aec32c659a268c54c382ff30d"
},
"downloads": -1,
"filename": "semimutable-0.1.0a0.tar.gz",
"has_sig": false,
"md5_digest": "58dd6916253960e6fbec1e654c6729d4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 16027,
"upload_time": "2025-07-21T05:13:30",
"upload_time_iso_8601": "2025-07-21T05:13:30.386785Z",
"url": "https://files.pythonhosted.org/packages/29/9e/91b70fb53c68e7f34e3c882c18340e5c30636a7700ab8fcb5eeed7da2a1f/semimutable-0.1.0a0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-21 05:13:30",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "semimutable"
}