From 0330bc07372a9c435c1e38f63f68ebe41a440cf6 Mon Sep 17 00:00:00 2001 From: TabulateJarl8 Date: Tue, 10 Sep 2024 14:32:58 -0400 Subject: [PATCH] fix B909 mutation to loop iterable during iteration --- vapor/api_interface.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vapor/api_interface.py b/vapor/api_interface.py index 4e85e28..523223e 100644 --- a/vapor/api_interface.py +++ b/vapor/api_interface.py @@ -252,9 +252,15 @@ async def parse_steam_user_games( # remove all of the games that we used that were already cached # this ensures that the timestamps of those games don't get updated game_ratings_copy = game_ratings.copy() - for game in game_ratings_copy: - if cache.get_game_data(game.app_id) is not None: - game_ratings_copy.remove(game) + games_to_remove: List[Game] = [ + game + for game in game_ratings_copy + if cache.get_game_data(game.app_id) is not None + ] + + # we do this in a seperate loop so that we're not mutating the iterable during iteration + for game in games_to_remove: + game_ratings_copy.remove(game) # update the game cache cache.update_cache(game_list=game_ratings)