Repository: qutebrowser/qutebrowser

Issue:
TypeError with refactored completion when searching for command
When doing `/:help` (or any other valid command, like `/:scroll`) we get a `TypeError`:

```
03:49:50 DEBUG    commands   command:run:511 command called: set-cmd-text ['/']
03:49:50 DEBUG    commands   command:run:526 Calling qutebrowser.mainwindow.statusbar.command.Command.set_cmd_text_command(<qutebrowser.mainwindow.statusbar.command.Command>, '/', False, False)
# [...]
03:49:51 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.command - delegating to <qutebrowser.keyinput.keyparser.PassthroughKeyParser mode='command' warn=True>
03:49:51 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: False, forward-unbound-keys: auto, passthrough: True, is_non_alnum: False --> filter: False (focused: <qutebrowser.mainwindow.statusbar.command.Command>)
03:49:51 DEBUG    completion completer:schedule_completion_update:221 Scheduling completion update.
03:49:51 DEBUG    completion completer:schedule_completion_update:218 Ignoring update because there were no changes.
03:49:51 DEBUG    completion completer:_partition:161 partitioning ['h'] around position 1
03:49:51 DEBUG    completion completer:_partition:173 partitioned: [] 'h' []
03:49:51 DEBUG    completion completer:_update_completion:232 Updating completion: [] h []
03:49:51 DEBUG    init       debug:__exit__:256 Reading history took 6.744919 seconds.
03:49:51 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: False
# [...]
03:49:51 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.command - delegating to <qutebrowser.keyinput.keyparser.PassthroughKeyParser mode='command' warn=True>
03:49:51 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: False, forward-unbound-keys: auto, passthrough: True, is_non_alnum: False --> filter: False (focused: <qutebrowser.mainwindow.statusbar.command.Command>)
03:49:51 DEBUG    completion completer:schedule_completion_update:221 Scheduling completion update.
03:49:51 DEBUG    completion completer:schedule_completion_update:218 Ignoring update because there were no changes.
03:49:51 DEBUG    completion completer:_update_completion:232 Updating completion: []  []
03:49:52 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: False
03:49:52 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.command - delegating to <qutebrowser.keyinput.keyparser.PassthroughKeyParser mode='command' warn=True>
03:49:52 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: False, forward-unbound-keys: auto, passthrough: True, is_non_alnum: True --> filter: False (focused: <qutebrowser.mainwindow.statusbar.command.Command>)
03:49:52 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.command - delegating to <qutebrowser.keyinput.keyparser.PassthroughKeyParser mode='command' warn=True>
03:49:52 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: False, forward-unbound-keys: auto, passthrough: True, is_non_alnum: False --> filter: False (focused: <qutebrowser.mainwindow.statusbar.command.Command>)
03:49:52 DEBUG    completion completer:schedule_completion_update:221 Scheduling completion update.
03:49:52 DEBUG    completion completer:schedule_completion_update:218 Ignoring update because there were no changes.
03:49:52 DEBUG    completion completer:_partition:161 partitioning [':'] around position 1
03:49:52 DEBUG    completion completer:_partition:173 partitioned: [] ':' []
03:49:52 DEBUG    completion completer:_update_completion:232 Updating completion: [] : []
03:49:52 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: False
03:49:52 DEBUG    misc       app:on_focus_object_changed:769 Focus object changed: <qutebrowser.mainwindow.statusbar.command.Command>
03:49:52 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: False
03:49:52 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.command - delegating to <qutebrowser.keyinput.keyparser.PassthroughKeyParser mode='command' warn=True>
03:49:52 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: False, forward-unbound-keys: auto, passthrough: True, is_non_alnum: False --> filter: False (focused: <qutebrowser.mainwindow.statusbar.command.Command>)
03:49:52 DEBUG    completion completer:schedule_completion_update:221 Scheduling completion update.
03:49:52 DEBUG    completion completer:schedule_completion_update:218 Ignoring update because there were no changes.
03:49:52 DEBUG    completion completer:_partition:161 partitioning [':h'] around position 2
03:49:52 DEBUG    completion completer:_partition:173 partitioned: [] ':h' []
03:49:52 DEBUG    completion completer:_update_completion:232 Updating completion: [] :h []
03:49:52 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: False
03:49:52 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.command - delegating to <qutebrowser.keyinput.keyparser.PassthroughKeyParser mode='command' warn=True>
03:49:52 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: False, forward-unbound-keys: auto, passthrough: True, is_non_alnum: False --> filter: False (focused: <qutebrowser.mainwindow.statusbar.command.Command>)
03:49:52 DEBUG    completion completer:schedule_completion_update:221 Scheduling completion update.
03:49:52 DEBUG    completion completer:schedule_completion_update:218 Ignoring update because there were no changes.
03:49:52 DEBUG    completion completer:_partition:161 partitioning [':he'] around position 3
03:49:52 DEBUG    completion completer:_partition:173 partitioned: [] ':he' []
03:49:52 DEBUG    completion completer:_update_completion:232 Updating completion: [] :he []
03:49:52 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: False
03:49:52 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.command - delegating to <qutebrowser.keyinput.keyparser.PassthroughKeyParser mode='command' warn=True>
03:49:52 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: False, forward-unbound-keys: auto, passthrough: True, is_non_alnum: False --> filter: False (focused: <qutebrowser.mainwindow.statusbar.command.Command>)
03:49:52 DEBUG    completion completer:schedule_completion_update:221 Scheduling completion update.
03:49:52 DEBUG    completion completer:schedule_completion_update:218 Ignoring update because there were no changes.
03:49:52 DEBUG    completion completer:_partition:161 partitioning [':hel'] around position 4
03:49:52 DEBUG    completion completer:_partition:173 partitioned: [] ':hel' []
03:49:52 DEBUG    completion completer:_update_completion:232 Updating completion: [] :hel []
03:49:52 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: False
03:49:53 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.command - delegating to <qutebrowser.keyinput.keyparser.PassthroughKeyParser mode='command' warn=True>
03:49:53 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: False, forward-unbound-keys: auto, passthrough: True, is_non_alnum: False --> filter: False (focused: <qutebrowser.mainwindow.statusbar.command.Command>)
03:49:53 DEBUG    completion completer:schedule_completion_update:221 Scheduling completion update.
03:49:53 DEBUG    completion completer:schedule_completion_update:218 Ignoring update because there were no changes.
03:49:53 DEBUG    completion completer:_partition:161 partitioning ['help'] around position 5
03:49:53 ERROR    misc       crashsignal:exception_hook:211 Uncaught exception
Traceback (most recent call last):
  File "/home/tom/git/qutebrowser/qutebrowser/completion/completer.py", line 229, in _update_completion
    before_cursor, pattern, after_cursor = self._partition()
TypeError: 'NoneType' object is not iterable
```



Discussion:

Resolving patch:
diff --git a/qutebrowser/completion/completer.py b/qutebrowser/completion/completer.py
--- a/qutebrowser/completion/completer.py
+++ b/qutebrowser/completion/completer.py
@@ -226,11 +226,6 @@ def schedule_completion_update(self):
     @pyqtSlot()
     def _update_completion(self):
         """Check if completions are available and activate them."""
-        before_cursor, pattern, after_cursor = self._partition()
-
-        log.completion.debug("Updating completion: {} {} {}".format(
-            before_cursor, pattern, after_cursor))
-
         if self._ignore_change:
             log.completion.debug("Ignoring completion update because "
                                  "ignore_change is True.")
@@ -247,6 +242,11 @@ def _update_completion(self):
             completion.set_model(None)
             return
 
+        before_cursor, pattern, after_cursor = self._partition()
+
+        log.completion.debug("Updating completion: {} {} {}".format(
+            before_cursor, pattern, after_cursor))
+
         pattern = pattern.strip("'\"")
         model = self._get_new_completion(before_cursor, pattern)
 


Test patch:
diff --git a/tests/unit/completion/test_completer.py b/tests/unit/completion/test_completer.py
--- a/tests/unit/completion/test_completer.py
+++ b/tests/unit/completion/test_completer.py
@@ -180,6 +180,7 @@ def _set_cmd_prompt(cmd, txt):
     (':set -t -p |', usertypes.Completion.section, ''),
     (':open -- |', None, ''),
     (':gibberish nonesense |', None, ''),
+    ('/:help|', None, ''),
 ])
 def test_update_completion(txt, kind, pattern, status_command_stub,
                            completer_obj, completion_widget_stub):