Skip to content

Commit

Permalink
Adds copy back in
Browse files Browse the repository at this point in the history
  • Loading branch information
spacether committed Jul 20, 2023
1 parent e2610f4 commit 830aece
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions immutabledict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def __getitem__(self, key: _K) -> _V:
def __contains__(self, key: object) -> bool:
return key in self._dict

def copy(self) -> immutabledict[_K, _V]:
return self.__class__(self)

def __iter__(self) -> Iterator[_K]:
return iter(self._dict)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_immutabledict.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ def test_cannot_assign_value(self):
with pytest.raises(AttributeError):
immutabledict().setitem("key", "value")

def test_copy(self):
original = immutabledict({"a": "value"})
copy = original.copy()
assert original == copy
assert id(original) != id(copy)


def test_from_keys(self):
keys = ("a", "b", "c")
immutable_dict = immutabledict.fromkeys(keys)
Expand Down

0 comments on commit 830aece

Please sign in to comment.