From cc4cee9c246e93a851c4a736b5e19ebe6ac6067b Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Mon, 25 Jan 2021 10:08:34 -0800 Subject: [PATCH] Annotations/lint (Flake8 E501): split long function definitions and their annotations. Re #155. --- addon/appModules/splstudio/__init__.py | 21 ++++++++++++++++----- addon/appModules/splstudio/splconfig.py | 22 +++++++++++++++++----- addon/appModules/splstudio/splmisc.py | 3 ++- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/addon/appModules/splstudio/__init__.py b/addon/appModules/splstudio/__init__.py index 17c2b5862..e69b0d71c 100644 --- a/addon/appModules/splstudio/__init__.py +++ b/addon/appModules/splstudio/__init__.py @@ -344,7 +344,9 @@ def doAction(self, index=None): # A convenience method that calls column content getter for a list of columns. # Readable flag will transform None into an empty string, suitable for output. # #61 (18.07): readable flag will become a string parameter to be used in columns viewer. - def _getColumnContents(self, columns: Optional[list[int]] = None, readable: bool = False) -> list[Optional[str]]: + def _getColumnContents( + self, columns: Optional[list[int]] = None, readable: bool = False + ) -> list[Optional[str]]: if columns is None: columns = list(range(18)) columnContents = [self._getColumnContentRaw(col) for col in columns] @@ -1215,7 +1217,9 @@ def terminate(self): # 6.0: Split this into two functions: the announcer (below) and formatter. # 7.0: The ms (millisecond) argument will be used when announcing playlist remainder. # 16.12: Include hours by default unless told not to do so. - def announceTime(self, t: int, offset: Optional[int] = None, ms: bool = True, includeHours: Optional[bool] = None) -> None: + def announceTime( + self, t: int, offset: Optional[int] = None, ms: bool = True, includeHours: Optional[bool] = None + ) -> None: if t <= 0: ui.message("00:00") else: @@ -1224,7 +1228,9 @@ def announceTime(self, t: int, offset: Optional[int] = None, ms: bool = True, in # Formatter: given time in milliseconds, convert it to human-readable format. # 7.0: There will be times when one will deal with time in seconds. # 16.12: For some cases, do not include hour slot when trying to conform to what Studio displays.) - def _ms2time(self, t: int, offset: Optional[int] = None, ms: bool = True, includeHours: Optional[bool] = None) -> str: + def _ms2time( + self, t: int, offset: Optional[int] = None, ms: bool = True, includeHours: Optional[bool] = None + ) -> str: if t <= 0: return "00:00" else: @@ -1381,7 +1387,9 @@ def script_setBrailleTimer(self, gesture): # 21.03: accept both None and str because it will be filtered to remove None anyway. findText: Optional[list[Optional[str]]] = None - def trackFinder(self, text: str, obj: Any, directionForward: bool = True, column: Optional[list[int]] = None) -> None: + def trackFinder( + self, text: str, obj: Any, directionForward: bool = True, column: Optional[list[int]] = None + ) -> None: speech.cancelSpeech() # #32 (17.06/15.8 LTS): Update search text even if the track with the search term in columns does not exist. # #27 (17.08): especially if the search history is empty. @@ -1412,7 +1420,10 @@ def trackFinder(self, text: str, obj: Any, directionForward: bool = True, column # Split from track finder in 2015. # Return a track with the given search criteria. # Column is a list of columns to be searched (if none, it'll be artist and title). - def _trackLocator(self, text: str, obj: Any = api.getFocusObject(), directionForward: bool = True, columns: Optional[list[int]] = None) -> Any: + def _trackLocator( + self, text: str, obj: Any = api.getFocusObject(), + directionForward: bool = True, columns: Optional[list[int]] = None + ) -> Any: nextTrack = "next" if directionForward else "previous" while obj is not None: # Do not use column content attribute, because sometimes NVDA will say diff --git a/addon/appModules/splstudio/splconfig.py b/addon/appModules/splstudio/splconfig.py index 59ef758f2..532596654 100755 --- a/addon/appModules/splstudio/splconfig.py +++ b/addon/appModules/splstudio/splconfig.py @@ -211,7 +211,10 @@ def instantSwitchProfileActive(self) -> bool: # Unlock (load) profiles from files. # 7.0: Allow new profile settings to be overridden by a parent profile. # 8.0: Don't validate profiles other than normal profile in the beginning. - def _unlockConfig(self, path: str, profileName: Optional[str] = None, prefill: bool = False, parent: Optional[dict[Any, Any]] = None, validateNow: bool = False) -> ConfigObj: + def _unlockConfig( + self, path: str, profileName: Optional[str] = None, prefill: bool = False, + parent: Optional[dict[Any, Any]] = None, validateNow: bool = False + ) -> ConfigObj: # 7.0: Suppose this is one of the steps taken when copying settings when instantiating a new profile. # If so, go through same procedure as though config passes validation tests, # as all values from parent are in the right format. @@ -253,7 +256,9 @@ def _unlockConfig(self, path: str, profileName: Optional[str] = None, prefill: b # Config validation. # Separated from unlock routine in 8.0. - def _validateConfig(self, SPLConfigCheckpoint: ConfigObj, profileName: Optional[str] = None, prefill: bool = False) -> None: + def _validateConfig( + self, SPLConfigCheckpoint: ConfigObj, profileName: Optional[str] = None, prefill: bool = False + ) -> None: global _configLoadStatus configTest = SPLConfigCheckpoint.validate(_val, copy=prefill, preserve_errors=True) # Validator may return "True" if everything is okay, @@ -483,7 +488,10 @@ def save(self) -> None: # Profile indicates the name of the profile to reset or reload. # Sometimes confirmation message will be shown, especially if instant switch profile is active. # Config dialog flag is a special flag reserved for use by add-on settings dialog. - def reset(self, factoryDefaults: bool = False, askForConfirmation: bool = False, resetViaConfigDialog: bool = False) -> None: + def reset( + self, factoryDefaults: bool = False, + askForConfirmation: bool = False, resetViaConfigDialog: bool = False + ) -> None: if resetViaConfigDialog: askForConfirmation = bool(factoryDefaults and self._switchProfileFlags) if askForConfirmation: @@ -581,7 +589,9 @@ def profileByName(self, name: str) -> ConfigObj: # Returns list of flags associated with a given profile. # Optional keyword arguments are to be added when called from dialogs such as add-on settings. # A crucial kwarg is contained, and if so, profile flags set will be returned. - def getProfileFlags(self, name: str, active: Optional[str] = None, instant: Optional[str] = None, contained: bool = False) -> Union[str, set[str]]: + def getProfileFlags( + self, name: str, active: Optional[str] = None, instant: Optional[str] = None, contained: bool = False + ) -> Union[str, set[str]]: flags = set() if active is None: active = self.activeProfile @@ -667,7 +677,9 @@ def switchProfileEnd(self, prevProfile: Optional[str], newProfile: str, switchTy # Used from config dialog and other places. # Show switch index is used when deleting profiles so it doesn't have to look up index for old profiles. - def swapProfiles(self, prevProfile: Optional[str], newProfile: str, showSwitchIndex: bool = False) -> Optional[int]: + def swapProfiles( + self, prevProfile: Optional[str], newProfile: str, showSwitchIndex: bool = False + ) -> Optional[int]: former = self.profileIndexByName(prevProfile if prevProfile is not None else self.switchHistory[-1]) current = self.profileIndexByName(newProfile) self.profiles[current], self.profiles[former] = self.profiles[former], self.profiles[current] diff --git a/addon/appModules/splstudio/splmisc.py b/addon/appModules/splstudio/splmisc.py index 0307cf957..2829c3d48 100755 --- a/addon/appModules/splstudio/splmisc.py +++ b/addon/appModules/splstudio/splmisc.py @@ -320,7 +320,8 @@ def _populateCarts( # if told to refresh, timestamps will be checked and updated banks will be reassigned. # Carts dictionary is used if and only if refresh is on, as it'll modify live carts. def cartExplorerInit( - StudioTitle: str, cartFiles: Optional[list[str]] = None, refresh: bool = False, carts: Optional[dict[str, Any]] = None + StudioTitle: str, cartFiles: Optional[list[str]] = None, + refresh: bool = False, carts: Optional[dict[str, Any]] = None ) -> dict[str, Any]: global _cartEditTimestamps log.debug("SPL: refreshing Cart Explorer" if refresh else "preparing cart Explorer")