Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid KeyError when deleting entry #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pylru.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __setitem__(self, key, value):
if not node.empty:
if self.callback is not None:
self.callback(node.key, node.value)
del self.table[node.key]
self.table.pop(node.key, None)

# Place the new key and value in the node
node.empty = False
Expand All @@ -156,7 +156,7 @@ def __setitem__(self, key, value):
def __delitem__(self, key):
# Lookup the node, remove it from the hash table, and mark it as empty.
node = self.table[key]
del self.table[key]
self.table.pop(key, None)
node.empty = True

# Not strictly necessary.
Expand Down Expand Up @@ -213,7 +213,7 @@ def popitem(self):
value = node.value

# Remove the key from the hash table and mark the node as empty.
del self.table[key]
self.table.pop(key, None)
node.empty = True

# Not strictly necessary.
Expand Down Expand Up @@ -296,7 +296,7 @@ def removeTailNode(self, n):
if not node.empty:
if self.callback is not None:
self.callback(node.key, node.value)
del self.table[node.key]
self.table.pop(node.key, None)

# Splice the tail node out of the list
self.head.prev = node.prev
Expand Down