A simple Python base class for immutable objects whose value is determined by a state tuple.
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
state-tuple-value-object
A simple Python base class for immutable objects whose value is determined by a state tuple.
Features
- Equality (
==) via__eq__ - Hashing via
__hash__for use in sets and as dictionary keys - Pickle support via
__reduce__ - Readable representation via
__repr__for easier debugging - Compatible with Python 2+
- Less dynamic features than
attrsordataclasses
Usage
- Inherit from
StateTupleValueObject - Implement
get_state_tuple(self)to return the state as a tuple - Benefit from automated equality, hashing, pickling, and representation
from state_tuple_value_object import StateTupleValueObject
class Point(StateTupleValueObject):
def __init__(self, x, y):
self.x = x
self.y = y
def get_state_tuple(self):
return (self.x, self.y)
p1 = Point(1, 2)
p2 = Point(1, 2)
p3 = Point(3, 4)
print(p1 == p2) # True
print(hash(p1) == hash(p2)) # True
print(p1) # Point(1, 2)
print(p1 == p3) # False
my_set = {p1, p2, p3}
print(my_set) # {Point(1, 2), Point(3, 4)}
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file state_tuple_value_object-0.1.0a0.tar.gz.
File metadata
- Download URL: state_tuple_value_object-0.1.0a0.tar.gz
- Upload date:
- Size: 2.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46e4f8489a283c4874de97805680e272f6e9e2e42b223fff08664d4414550acb
|
|
| MD5 |
674e64ebf17f874356d23efee8fdf660
|
|
| BLAKE2b-256 |
581098ef33a65dae8832e20e1d9bd82fae16a36f2d09a8442d25bf4bc95e7d34
|
File details
Details for the file state_tuple_value_object-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: state_tuple_value_object-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c68e9ffcf1c17b67578d704fda92b0881fc25ac7cd287dd59b01af0c6cd4f948
|
|
| MD5 |
78dfbe62b6dff5e45c981186c766b528
|
|
| BLAKE2b-256 |
5d82a6c4d9fd8ade4a32a9b7c80e55fbcf1dea28c50244408541e6acdd97777a
|