Skip to content

Commit

Permalink
Annotations/lint (Flake8 E501): split long function definitions and t…
Browse files Browse the repository at this point in the history
…heir annotations. Re #155.
  • Loading branch information
josephsl committed Jan 25, 2021
1 parent 2a4c359 commit cc4cee9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
21 changes: 16 additions & 5 deletions addon/appModules/splstudio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions addon/appModules/splstudio/splconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion addon/appModules/splstudio/splmisc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit cc4cee9

Please sign in to comment.