diff options
author | Florian Bruhin <me@the-compiler.org> | 2019-10-09 17:53:47 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2019-10-09 18:08:03 +0200 |
commit | c03397e8acf4c59ad679e8153e5691156576b30f (patch) | |
tree | a1a401a7238effacef62cca90a042789a3b742ac /qutebrowser/keyinput/macros.py | |
parent | 038c6e495b6f65e29f8d742846e21bdb12b12759 (diff) | |
download | qutebrowser-c03397e8acf4c59ad679e8153e5691156576b30f.tar.gz qutebrowser-c03397e8acf4c59ad679e8153e5691156576b30f.zip |
Add type annotations for keyinput.macros
Diffstat (limited to 'qutebrowser/keyinput/macros.py')
-rw-r--r-- | qutebrowser/keyinput/macros.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/qutebrowser/keyinput/macros.py b/qutebrowser/keyinput/macros.py index a0116c19f..7a694fe1e 100644 --- a/qutebrowser/keyinput/macros.py +++ b/qutebrowser/keyinput/macros.py @@ -20,12 +20,17 @@ """Keyboard macro system.""" +import typing + from qutebrowser.commands import runners from qutebrowser.api import cmdutils from qutebrowser.keyinput import modeman from qutebrowser.utils import message, objreg, usertypes +_CommandType = typing.Tuple[str, int] # command, type + + class MacroRecorder: """An object for recording and running keyboard macros. @@ -39,15 +44,15 @@ class MacroRecorder: _last_register: The macro which did run last. """ - def __init__(self): - self._macros = {} - self._recording_macro = None - self._macro_count = {} - self._last_register = None + def __init__(self) -> None: + self._macros = {} # type: typing.Dict[str, typing.List[_CommandType]] + self._recording_macro = None # type: typing.Optional[str] + self._macro_count = {} # type: typing.Dict[int, int] + self._last_register = None # type: typing.Optional[str] @cmdutils.register(instance='macro-recorder', name='record-macro') @cmdutils.argument('win_id', value=cmdutils.Value.win_id) - def record_macro_command(self, win_id, register=None): + def record_macro_command(self, win_id: int, register: str = None) -> None: """Start or stop recording a macro. Args: @@ -64,7 +69,7 @@ class MacroRecorder: message.info("Macro '{}' recorded.".format(self._recording_macro)) self._recording_macro = None - def record_macro(self, register): + def record_macro(self, register: str) -> None: """Start recording a macro.""" message.info("Recording macro '{}'...".format(register)) self._macros[register] = [] @@ -73,7 +78,9 @@ class MacroRecorder: @cmdutils.register(instance='macro-recorder', name='run-macro') @cmdutils.argument('win_id', value=cmdutils.Value.win_id) @cmdutils.argument('count', value=cmdutils.Value.count) - def run_macro_command(self, win_id, count=1, register=None): + def run_macro_command(self, win_id: int, + count: int = 1, + register: str = None) -> None: """Run a recorded macro. Args: @@ -87,7 +94,7 @@ class MacroRecorder: else: self.run_macro(win_id, register) - def run_macro(self, win_id, register): + def run_macro(self, win_id: int, register: str) -> None: """Run a recorded macro.""" if register == '@': if self._last_register is None: @@ -104,13 +111,13 @@ class MacroRecorder: for cmd in self._macros[register]: commandrunner.run_safely(*cmd) - def record_command(self, text, count): + def record_command(self, text: str, count: int) -> None: """Record a command if a macro is being recorded.""" if self._recording_macro is not None: self._macros[self._recording_macro].append((text, count)) -def init(): +def init() -> None: """Initialize the MacroRecorder.""" macro_recorder = MacroRecorder() objreg.register('macro-recorder', macro_recorder) |