Skip to content

Commit

Permalink
ConfigHub: annotate class attributes from constructor. Re #155.
Browse files Browse the repository at this point in the history
Annotate ConfigHub class attributes to better communicate attribute types and to guard against potential bugs due to type misuse.
  • Loading branch information
josephsl committed Jan 25, 2021
1 parent aced8a1 commit e5d989e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions addon/appModules/splstudio/splconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ def __init__(self, splComponent: Optional[str] = None) -> None:
# #155 (21.03): re-initialize maps to be a list of config objects to satisfy Mypy and friends.
self.maps: list[ConfigObj] = [{}]
# #64 (18.07): keep an eye on which SPL component opened this map.
self.splComponents = set()
self.splComponents: set[str] = set()
self.splComponents.add(splComponent)
# 17.10: config restrictions such as in-memory config come from command line.
self._configInMemory = "--spl-configinmemory" in globalVars.appArgsExtra
self._normalProfileOnly = "--spl-normalprofileonly" in globalVars.appArgsExtra
self._configInMemory: bool = "--spl-configinmemory" in globalVars.appArgsExtra
self._normalProfileOnly: bool = "--spl-normalprofileonly" in globalVars.appArgsExtra
if self.configInMemory:
self._normalProfileOnly = True
# For presentational purposes.
self.profileNames = []
self.profileNames: list[Optional[str]] = []
# 17.10: if config will be stored on RAM, this step is skipped, resulting in faster startup.
# But data conversion must take place.
if not self.configInMemory:
Expand Down Expand Up @@ -169,16 +169,16 @@ def __init__(self, splComponent: Optional[str] = None) -> None:
self.instantSwitch = self.profiles[0]["InstantProfile"]
else:
self.instantSwitch = None
self.prevProfile = None
self.prevProfile: Optional[str] = None
# A bit vector used to store profile switching flags.
self._switchProfileFlags = 0
self._switchProfileFlags: int = 0
# Switch history is a stack of previously activated profile(s), replacing prev profile flag from 7.x days.
# Initially normal profile will sit in here.
self.switchHistory = [self.activeProfile]
self.switchHistory: list[str] = [self.activeProfile]
# Record new profiles if any.
self.newProfiles = set()
self.newProfiles: set[str] = set()
# Reset flag (only engaged if reset did happen).
self.resetHappened = False
self.resetHappened: bool = False
# #73: listen to config save/reset actions from NVDA Core.
config.post_configSave.register(self.save)
config.post_configReset.register(self.handlePostConfigReset)
Expand All @@ -201,7 +201,7 @@ def configRestricted(self) -> bool:
return self.normalProfileOnly or self.configInMemory

# Profile switching flags.
_profileSwitchFlags = {"instant": 0x1}
_profileSwitchFlags: dict[str, int] = {"instant": 0x1}

@property
def switchProfileFlags(self) -> int:
Expand Down

0 comments on commit e5d989e

Please sign in to comment.