Skip to content

Commit

Permalink
Fix KeyError in inventory.py
Browse files Browse the repository at this point in the history
When we have no items of type, there are no "count" key in the dict.
  • Loading branch information
cmezh committed Aug 11, 2016
1 parent 42e9d9c commit ed2769c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pokemongo_bot/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ class Items(_BaseInventoryComponent):
STATIC_DATA_FILE = os.path.join(_base_dir, 'data', 'items.json')

def count_for(self, item_id):
return self._data[item_id]['count']
try:
return self._data[item_id]['count']
except KeyError:
return 0

def decrement_count(self, item_id):
self._data[item_id]["count"] -= 1
Expand Down

0 comments on commit ed2769c

Please sign in to comment.