Skip to content

Commit

Permalink
basic behavior working
Browse files Browse the repository at this point in the history
  • Loading branch information
maccam912 committed Oct 16, 2022
1 parent 93beb98 commit 41144e9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "add-only-dictionary"
version = "0.1.1"
version = "0.1.2"
description = "Add Only Dictionary"
authors = ["Matt Koski <[email protected]>"]
license = "MIT"
Expand Down
10 changes: 8 additions & 2 deletions src/add_only_dictionary/aodict.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ class AODict(Dict[K, V]):
"""AODict class."""

def __setitem__(self, k: K, v: V) -> None:
"""__setitem__."""
super().__setitem__(k, v)
"""Lets you add item to dict, but not if key exists.
Args:
k (K): the key of attempted addition
v (V): the value
"""
if k not in self.keys():
super().__setitem__(k, v)
11 changes: 10 additions & 1 deletion tests/test_aodict.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@


def test_instantiate() -> None:
"""Just a sanity check to see if AODict can be created."""
"""Just a sanity check to see if AODict works."""
ao: AODict[str, int] = AODict()
ao["a"] = 1
assert ao["a"] == 1


def test_no_overwrite() -> None:
"""Make sure if the key is already in the dict, it can't be updated."""
ao: AODict[str, int] = AODict()
ao["a"] = 1
ao["a"] = 2
assert ao["a"] == 1

0 comments on commit 41144e9

Please sign in to comment.