No immutability
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.2k
- Forks
- 280
- Avg merge
- 6d 17h
- Merged PRs (30d)
- 4
Description
I just noticed one issue with dissoc on dictionaries.
diff --git a/toolz/tests/test_dicttoolz.py b/toolz/tests/test_dicttoolz.py
index 9134276..9b9a735 100644
--- a/toolz/tests/test_dicttoolz.py
+++ b/toolz/tests/test_dicttoolz.py
@@ -103,6 +103,10 @@ class TestDict(object):
assert d is oldd
assert d2 is not oldd
+ d = D({'x': {'a': 1}, 'y': 1})
+ d2 = dissoc(d, 'y')
+ assert id(d['x']) != id(d2['x'])
+
def test_update_in(self):
D, kw = self.D, self.kw
assert update_in(D({"a": 0}), ["a"], inc, **kw) == D({"a": 1})
I just added an example test to see that it fails, in short if you have nested dictionaries copy.copy doesn't create completely new and independent objects, but subobjects are shared.
Using copy.deepcopy instead would do the trick (but it's slower obviously)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with toolz/tests/test_dicttoolz.py and run the added dissoc case to reproduce the nested-dictionary aliasing. Then trace dissoc and its copying behavior; done means the test passes with nested values independent between the original and returned dictionaries, while accounting for the stated performance tradeoff.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100