From ebfdf98612b76969260d1ea67432bdad1d470def Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sun, 20 Mar 2022 18:56:59 +0000 Subject: [PATCH] Polish typing, explicit returns to terminate context managers --- app/dbconfig.py | 22 ++++++++++++++++++++-- app/musicmuster.py | 1 + app/playlists.py | 7 ++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/dbconfig.py b/app/dbconfig.py index c262c15..856d357 100644 --- a/app/dbconfig.py +++ b/app/dbconfig.py @@ -7,6 +7,23 @@ from contextlib import contextmanager from log import DEBUG from sqlalchemy.orm import (sessionmaker, scoped_session) + +class Counter: + def __init__(self): + self.count = 0 + + def __repr__(self): + return(f"") + + def inc(self): + self.count += 1 + return self.count + + def dec(self): + self.count -= 1 + return self.count + + MM_ENV = os.environ.get('MM_ENV', 'PRODUCTION') testing = False @@ -46,9 +63,10 @@ def Session(): file = frame.filename function = frame.function lineno = frame.lineno - DEBUG(f"Session acquired, {file=}, {function=}, {lineno=}") Session = scoped_session(sessionmaker(bind=engine)) + DEBUG(f"Session acquired, {file=}, {function=}, {lineno=}, {Session=}", + True) yield Session - DEBUG(" Session released") + DEBUG(" Session released", True) Session.commit() Session.close() diff --git a/app/musicmuster.py b/app/musicmuster.py index 2c4759f..834cc23 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -116,6 +116,7 @@ class Window(QMainWindow, Ui_MainWindow): record = Settings.get_int_settings(session, "mainwindow_height") height = record.f_int or 981 self.setGeometry(x, y, width, height) + return @staticmethod def kae(): diff --git a/app/playlists.py b/app/playlists.py index eb9f9dc..66bd21a 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -963,6 +963,7 @@ class PlaylistTab(QTableWidget): note_object = self._get_row_notes_object(row, session) if note_object: item.setText(note_object.note) + return def _clear_current_track_row(self) -> None: """ @@ -1178,7 +1179,7 @@ class PlaylistTab(QTableWidget): track = Tracks.get_by_id(session, track_id) return track - def _get_track_rows(self) -> Optional[List[int]]: + def _get_track_rows(self) -> List[int]: """Return rows marked as tracks, or None""" return self._meta_notset(RowMeta.NOTE) @@ -1304,7 +1305,7 @@ class PlaylistTab(QTableWidget): return self.item(row, self.COL_USERDATA).data(self.ROW_METADATA) - def _meta_notset(self, metadata: int) -> Union[List[int]]: + def _meta_notset(self, metadata: int) -> List[int]: """ Search rows for metadata not set. @@ -1371,7 +1372,7 @@ class PlaylistTab(QTableWidget): DEBUG(f"_rescan({row=})") with Session() as session: - for row in self._get_track_rows(): + if row in self._get_track_rows(): track: Tracks = self._get_row_track_object(row, session) if track: track.rescan(session)