Polish typing, explicit returns to terminate context managers

This commit is contained in:
Keith Edmunds 2022-03-20 18:56:59 +00:00
parent 0fb1536055
commit ebfdf98612
3 changed files with 25 additions and 5 deletions

View File

@ -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"<Counter({self.count=})>")
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()

View File

@ -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():

View File

@ -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)