Skip to content
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
17 changes: 8 additions & 9 deletions tinydb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,23 @@ def __delitem__(self, key: K) -> None:
del self.cache[key]

def __getitem__(self, key) -> V:
value = self.get(key)
if value is None:
if key not in self.cache:
raise KeyError(key)
value = self.cache[key]
self.cache.move_to_end(key, last=True)

return value

def __iter__(self) -> Iterator[K]:
return iter(self.cache)

def get(self, key: K, default: Optional[D] = None) -> Optional[Union[V, D]]:
value = self.cache.get(key)
if key not in self.cache:
return default
value = self.cache[key]
self.cache.move_to_end(key, last=True)

if value is not None:
self.cache.move_to_end(key, last=True)

return value

return default
return value

def set(self, key: K, value: V):
if key in self.cache:
Expand Down