You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add equality and hash methods for Table and Transaction (#16)
* docs: update changelog
* feat: add equality and hash methods for Table and Transaction
Implement __eq__ and __hash__ for both Table and Transaction classes:
- Table: value-based equality comparing resolved path, key_specifier,
and record state. Auto-reloads both tables before comparison.
- Transaction: equality based on parent table identity (is), finalized
status, and snapshot state.
- Both classes raise TypeError on hash (mutable objects).
Includes comprehensive tests and documentation updates.
Copy file name to clipboardExpand all lines: README.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,6 +149,23 @@ print(len(table))
149
149
150
150
Methods like `pop()`, `setdefault()`, and `update()` also work. The `keys()`, `values()`, and `items()` methods return sorted lists rather than views to maintain JSONLT's deterministic key ordering.
151
151
152
+
## Equality
153
+
154
+
Tables support value-based equality comparison:
155
+
156
+
```python
157
+
table1 = Table("users.jsonlt", key="id")
158
+
table2 = Table("users.jsonlt", key="id")
159
+
160
+
# Equal if same path, key specifier, and records
161
+
if table1 == table2:
162
+
print("Tables have identical content")
163
+
```
164
+
165
+
Two tables are equal when they have the same resolved path, key specifier, and record state. Transactions are equal when they reference the same parent table instance and have identical snapshot state.
166
+
167
+
Tables and transactions are mutable and therefore not hashable (cannot be used as dictionary keys or in sets).
0 commit comments