A few minor code cleanups and fixes (#47)
* Avoid exception if trying to delete missing "removed" key `.pop(key)` throws an exception if that `key` is missing. Using a default value (in this case None) means we don't throw any errors when deleting a missing key. Which is what we want here, for safety. We just want to delete the key. We don't care if it's existing or not. There are other places in the codebase that also use `.pop(key)`, but all of those first check the validity of the key before popping, so this was the only one that needed fixing. * Improve performance by removing keys() calls Every `.keys()` call create a new `[list...]` of all keys from the given dictionary. It's a total waste of performance, since we can already check if a key exists in a dictionary by just using `if "key" in the_dict`. * Use more pythonic "not in" syntax The syntax is supposed to be `if "thing" not in other_thing`. We already use this proper `not in` syntax everywhere else in the codebase. Just fixing this location.
This commit is contained in:
@@ -285,7 +285,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
def undo_remove_all(self, _widget, _unused):
|
||||
for game_id in self.removed_games:
|
||||
data = get_games([game_id])[game_id]
|
||||
if "removed" in data.keys():
|
||||
if "removed" in data:
|
||||
data.pop("removed")
|
||||
save_game(data)
|
||||
self.parent_widget.update_games(self.removed_games)
|
||||
@@ -294,7 +294,7 @@ class PreferencesWindow(Adw.PreferencesWindow):
|
||||
|
||||
def remove_all_games(self, _widget):
|
||||
for game in get_games().values():
|
||||
if not "removed" in game.keys():
|
||||
if "removed" not in game:
|
||||
self.removed_games.append(game["game_id"])
|
||||
game["removed"] = True
|
||||
save_game(game)
|
||||
|
||||
Reference in New Issue
Block a user