From ec3ad8a9698f6c936a0f63281ea34ae16101f03e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 27 Feb 2018 10:55:16 +0100 Subject: [PATCH] Get rid of _warn_on_keychains and _supports_chains --- qutebrowser/keyinput/basekeyparser.py | 26 ++----------------- qutebrowser/keyinput/keyparser.py | 13 ++++------ qutebrowser/keyinput/modeman.py | 3 +-- qutebrowser/keyinput/modeparsers.py | 15 ++++------- tests/unit/keyinput/test_basekeyparser.py | 31 +---------------------- 5 files changed, 14 insertions(+), 74 deletions(-) diff --git a/qutebrowser/keyinput/basekeyparser.py b/qutebrowser/keyinput/basekeyparser.py index 35c3c8c6d..ec1004316 100644 --- a/qutebrowser/keyinput/basekeyparser.py +++ b/qutebrowser/keyinput/basekeyparser.py @@ -48,13 +48,9 @@ class BaseKeyParser(QObject): Attributes: bindings: Bound key bindings _win_id: The window ID this keyparser is associated with. - _warn_on_keychains: Whether a warning should be logged when binding - keychains in a section which does not support them. _sequence: The currently entered key sequence _modename: The name of the input mode associated with this keyparser. _supports_count: Whether count is supported - # FIXME is this still needed? - _supports_chains: Whether keychains are supported Signals: keystring_updated: Emitted when the keystring is updated. @@ -70,24 +66,18 @@ class BaseKeyParser(QObject): do_log = True passthrough = False - def __init__(self, win_id, parent=None, supports_count=None, - supports_chains=False): + def __init__(self, win_id, parent=None, supports_count=True): super().__init__(parent) self._win_id = win_id self._modename = None self._sequence = keyutils.KeySequence() self._count = '' - if supports_count is None: - supports_count = supports_chains self._supports_count = supports_count - self._supports_chains = supports_chains - self._warn_on_keychains = True self.bindings = {} config.instance.changed.connect(self._on_config_changed) def __repr__(self): - return utils.get_repr(self, supports_count=self._supports_count, - supports_chains=self._supports_chains) + return utils.get_repr(self, supports_count=self._supports_count) def _debug_log(self, message): """Log a message to the debug log if logging is active. @@ -195,10 +185,6 @@ class BaseKeyParser(QObject): """ match = self._handle_key(e) - # FIXME - # if handled or not self._supports_chains: - # return handled - # don't emit twice if the keystring was cleared in self.clear_keystring if self._sequence: self.keystring_updated.emit(self._count + str(self._sequence)) @@ -232,14 +218,6 @@ class BaseKeyParser(QObject): assert cmd self.bindings[key] = cmd - # FIXME - # def _parse_key_command(self, modename, key, cmd): - # """Parse the keys and their command and store them in the object.""" - # elif self._warn_on_keychains: - # log.keyboard.warning("Ignoring keychain '{}' in mode '{}' " - # "because keychains are not supported there." - # .format(key, modename)) - def execute(self, cmdstr, count=None): """Handle a completed keychain. diff --git a/qutebrowser/keyinput/keyparser.py b/qutebrowser/keyinput/keyparser.py index 9914f0686..4e7f032d0 100644 --- a/qutebrowser/keyinput/keyparser.py +++ b/qutebrowser/keyinput/keyparser.py @@ -34,9 +34,8 @@ class CommandKeyParser(BaseKeyParser): _commandrunner: CommandRunner instance. """ - def __init__(self, win_id, parent=None, supports_count=None, - supports_chains=False): - super().__init__(win_id, parent, supports_count, supports_chains) + def __init__(self, win_id, parent=None, supports_count=None): + super().__init__(win_id, parent, supports_count) self._commandrunner = runners.CommandRunner(win_id) def execute(self, cmdstr, count=None): @@ -60,7 +59,7 @@ class PassthroughKeyParser(CommandKeyParser): # do_log = False passthrough = True - def __init__(self, win_id, mode, parent=None, warn=True): + def __init__(self, win_id, mode, parent=None): """Constructor. Args: @@ -68,11 +67,9 @@ class PassthroughKeyParser(CommandKeyParser): parent: Qt parent. warn: Whether to warn if an ignored key was bound. """ - super().__init__(win_id, parent, supports_chains=False) - self._warn_on_keychains = warn + super().__init__(win_id, parent) self._read_config(mode) self._mode = mode def __repr__(self): - return utils.get_repr(self, mode=self._mode, - warn=self._warn_on_keychains) + return utils.get_repr(self, mode=self._mode) diff --git a/qutebrowser/keyinput/modeman.py b/qutebrowser/keyinput/modeman.py index e32830f50..75e3af367 100644 --- a/qutebrowser/keyinput/modeman.py +++ b/qutebrowser/keyinput/modeman.py @@ -71,8 +71,7 @@ def init(win_id, parent): KM.passthrough: keyparser.PassthroughKeyParser(win_id, 'passthrough', modeman), KM.command: keyparser.PassthroughKeyParser(win_id, 'command', modeman), - KM.prompt: keyparser.PassthroughKeyParser(win_id, 'prompt', modeman, - warn=False), + KM.prompt: keyparser.PassthroughKeyParser(win_id, 'prompt', modeman), KM.yesno: modeparsers.PromptKeyParser(win_id, modeman), KM.caret: modeparsers.CaretKeyParser(win_id, modeman), KM.set_mark: modeparsers.RegisterKeyParser(win_id, KM.set_mark, diff --git a/qutebrowser/keyinput/modeparsers.py b/qutebrowser/keyinput/modeparsers.py index 89f8f5ddb..9c44e4818 100644 --- a/qutebrowser/keyinput/modeparsers.py +++ b/qutebrowser/keyinput/modeparsers.py @@ -48,8 +48,7 @@ class NormalKeyParser(keyparser.CommandKeyParser): """ def __init__(self, win_id, parent=None): - super().__init__(win_id, parent, supports_count=True, - supports_chains=True) + super().__init__(win_id, parent, supports_count=True) self._read_config('normal') self._partial_timer = usertypes.Timer(self, 'partial-match') self._partial_timer.setSingleShot(True) @@ -131,8 +130,7 @@ class PromptKeyParser(keyparser.CommandKeyParser): """KeyParser for yes/no prompts.""" def __init__(self, win_id, parent=None): - super().__init__(win_id, parent, supports_count=False, - supports_chains=True) + super().__init__(win_id, parent, supports_count=False) self._read_config('yesno') def __repr__(self): @@ -149,8 +147,7 @@ class HintKeyParser(keyparser.CommandKeyParser): """ def __init__(self, win_id, parent=None): - super().__init__(win_id, parent, supports_count=False, - supports_chains=True) + super().__init__(win_id, parent, supports_count=False) self._filtertext = '' self._last_press = LastPress.none self._read_config('hint') @@ -261,8 +258,7 @@ class CaretKeyParser(keyparser.CommandKeyParser): passthrough = True def __init__(self, win_id, parent=None): - super().__init__(win_id, parent, supports_count=True, - supports_chains=True) + super().__init__(win_id, parent, supports_count=True) self._read_config('caret') @@ -276,8 +272,7 @@ class RegisterKeyParser(keyparser.CommandKeyParser): """ def __init__(self, win_id, mode, parent=None): - super().__init__(win_id, parent, supports_count=False, - supports_chains=False) + super().__init__(win_id, parent, supports_count=False) self._mode = mode self._read_config('register') diff --git a/tests/unit/keyinput/test_basekeyparser.py b/tests/unit/keyinput/test_basekeyparser.py index ce660777f..0a8d44c60 100644 --- a/tests/unit/keyinput/test_basekeyparser.py +++ b/tests/unit/keyinput/test_basekeyparser.py @@ -19,7 +19,6 @@ """Tests for BaseKeyParser.""" -import logging from unittest import mock from PyQt5.QtCore import Qt @@ -37,8 +36,7 @@ def keyseq(s): @pytest.fixture def keyparser(key_config_stub): """Fixture providing a BaseKeyParser supporting count/chains.""" - kp = basekeyparser.BaseKeyParser( - 0, supports_count=True, supports_chains=True) + kp = basekeyparser.BaseKeyParser(0, supports_count=True) kp.execute = mock.Mock() yield kp @@ -56,19 +54,6 @@ def handle_text(fake_keyevent_factory, keyparser): return func -@pytest.mark.parametrize('count, chains, count_expected, chains_expected', [ - (True, False, True, False), - (False, True, False, True), - (None, True, True, True), -]) -def test_supports_args(config_stub, count, chains, count_expected, - chains_expected): - kp = basekeyparser.BaseKeyParser( - 0, supports_count=count, supports_chains=chains) - assert kp._supports_count == count_expected - assert kp._supports_chains == chains_expected - - class TestDebugLog: """Make sure _debug_log only logs when do_log is set.""" @@ -154,20 +139,6 @@ class TestReadConfig: assert keyseq('a') in keyparser.bindings assert (keyseq('new') in keyparser.bindings) == expected - # FIXME do we still need this? - @pytest.mark.parametrize('warn_on_keychains', [True, False]) - @pytest.mark.skip(reason='unneeded?') - def test_warn_on_keychains(self, caplog, warn_on_keychains): - """Test _warn_on_keychains.""" - kp = basekeyparser.BaseKeyParser( - 0, supports_count=False, supports_chains=False) - kp._warn_on_keychains = warn_on_keychains - - with caplog.at_level(logging.WARNING): - kp._read_config('normal') - - assert bool(caplog.records) == warn_on_keychains - class TestSpecialKeys: