From 0c7a4a4a4c5bbe18566011b96f55f8fe5c684991 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 28 Dec 2021 17:19:09 -0500 Subject: [PATCH] db: Use the new match / case statement in user.py:do_factory() This is cleaner than using a bunch of elif-s to pick the right playlist type Signed-off-by: Anna Schumaker --- db/user.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/db/user.py b/db/user.py index 53ee82e..6d9d51a 100644 --- a/db/user.py +++ b/db/user.py @@ -140,17 +140,19 @@ class UserTable(playlist.Model): sql.execute("DROP TABLE temp_playlist_map") def do_factory(self, row): - if row["name"] == "Collection": - return Collection(row) - elif row["name"] == "Favorites": - return UserPlaylist(row, "emmental-favorites", "playlist_map") - elif row["name"] == "New Tracks": - return UserPlaylist(row, "starred", "temp_playlist_map") - elif row["name"] == "Previous": - return Previous(row) - elif row["name"] == "Queued Tracks": - return QueuedTracks(row) - return UserPlaylist(row, "audio-x-generic", "playlist_map") + match row["name"]: + case "Collection": + return Collection(row) + case "Favorites": + return UserPlaylist(row, "emmental-favorites", "playlist_map") + case "New Tracks": + return UserPlaylist(row, "starred", "temp_playlist_map") + case "Previous": + return Previous(row) + case "Queued Tracks": + return QueuedTracks(row) + case _: + return UserPlaylist(row, "audio-x-generic", "playlist_map") def do_insert(self, plstate, name): return sql.execute("INSERT INTO playlists (plstateid, name, sort) "