Repository: qutebrowser/qutebrowser

Issue:
AttributeError: 'NoneType' object has no attribute 'elems' with number hints
On f597b05 when doing this:
- `qutebrowser --temp-basedir -s hints mode number tests/end2end/data/hints/number.html`
- `;r`
- `<esc>`
- `;r`
- `00`

We get:

```
Traceback (most recent call last):
  File "/home/florian/proj/qutebrowser/git/qutebrowser/app.py", line 862, in eventFilter
    return handler(event)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/app.py", line 822, in _handle_key_event
    return man.eventFilter(event)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/modeman.py", line 318, in eventFilter
    return self._eventFilter_keypress(event)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/modeman.py", line 170, in _eventFilter_keypress
    handled = parser.handle(event)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/modeparsers.py", line 211, in handle
    match = self._handle_single_key(e)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/basekeyparser.py", line 197, in _handle_single_key
    self.execute(binding, self.Type.chain, count)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/modeparsers.py", line 234, in execute
    hintmanager.fire(cmdstr)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/browser/hints.py", line 1044, in fire
    for string, elem in self._context.elems.items():
AttributeError: 'NoneType' object has no attribute 'elems'
```

log:

```
14:13:29 DEBUG    commands   command:run:508 command called: hint ['--rapid', 'links', 'tab-bg']
14:13:29 DEBUG    commands   command:run:523 Calling qutebrowser.browser.hints.HintManager.start(<qutebrowser.browser.hints.HintManager object at 0x7f38640be948>, True, <Group.links: 2>, <Target.tab_bg: 5>, win_id=0)
14:13:29 DEBUG    hints      hints:_init_elements:706 hints: 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10
14:13:29 DEBUG    message    message:set_text:363 Follow hint in background tab (rapid mode)...
14:13:29 DEBUG    statusbar  text:set_text:55 Setting normal text to 'Follow hint in background tab (rapid mode)...'.
14:13:29 DEBUG    hints      hints:_connect_frame_signals:668 Connecting frame <PyQt5.QtWebKitWidgets.QWebFrame object at 0x7f385dcb9948>
14:13:29 DEBUG    modes      modeman:enter:240 Entering mode KeyMode.hint (reason: HintManager.start)
14:13:29 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: True, forward-unbound-keys: auto, passthrough: False, is_non_alnum: False --> filter: True (focused: <qutebrowser.browser.webkit.webview.WebView tab_id=0 url='file:///home/florian/proj/qutebrowser/git/tests/end2end/data/hints/number.html'>)
14:13:29 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: True
14:13:29 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: True
14:13:30 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.hint - delegating to <qutebrowser.keyinput.modeparsers.HintKeyParser supports_chains=True supports_count=False>
14:13:30 DEBUG    keyboard   basekeyparser:_debug_log:111 Got key: 0x30 / text: '0'
14:13:30 DEBUG    keyboard   basekeyparser:_debug_log:111 No match for '0' (added 0)
14:13:30 DEBUG    hints      hints:handle_partial_key:874 Handling new keystring: '0'
14:13:30 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: True, forward-unbound-keys: auto, passthrough: False, is_non_alnum: False --> filter: True (focused: <qutebrowser.browser.webkit.webview.WebView tab_id=0 url='file:///home/florian/proj/qutebrowser/git/tests/end2end/data/hints/number.html'>)
14:13:30 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: True
14:13:31 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.hint - delegating to <qutebrowser.keyinput.modeparsers.HintKeyParser supports_chains=True supports_count=False>
14:13:31 DEBUG    keyboard   basekeyparser:_debug_log:111 Got key: 0x30 / text: '0'
14:13:31 DEBUG    keyboard   basekeyparser:_debug_log:111 Definitive match for '00'.
14:13:31 DEBUG    hints      hints:_click:461 Clicking on '<a href="/data/numbers/1.txt">one</a>' at position PyQt5.QtCore.QPoint(59, 190)
14:13:31 DEBUG    webview    webpage:on_start_hinting:432 Setting force target to ClickTarget.tab_bg
14:13:31 DEBUG    modes      webview:on_mouse_event:302 Hint triggered, focusing <qutebrowser.browser.webkit.webview.WebView tab_id=0 url='file:///home/florian/proj/qutebrowser/git/tests/end2end/data/hints/number.html'>
14:13:31 DEBUG    modes      webview:on_mouse_event:302 Hint triggered, focusing <qutebrowser.browser.webkit.webview.WebView tab_id=0 url='file:///home/florian/proj/qutebrowser/git/tests/end2end/data/hints/number.html'>
14:13:31 DEBUG    modes      webview:on_mouse_event:302 Hint triggered, focusing <qutebrowser.browser.webkit.webview.WebView tab_id=0 url='file:///home/florian/proj/qutebrowser/git/tests/end2end/data/hints/number.html'>
14:13:31 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: True, forward-unbound-keys: auto, passthrough: False, is_non_alnum: False --> filter: True (focused: <qutebrowser.browser.webkit.webview.WebView tab_id=0 url='file:///home/florian/proj/qutebrowser/git/tests/end2end/data/hints/number.html'>)
14:13:31 DEBUG    misc       webelem:is_editable:262 Checking if element is editable: <qutebrowser.browser.webkit.webelem.WebElementWrapper html='<a href="/data/numbers/1.txt">one</a>'>
14:13:31 DEBUG    mouse      webview:_mousepress_insertmode:219 Clicked non-editable element!
14:13:31 DEBUG    modes      modeman:maybe_leave:114 Not in mode KeyMode.insert! (leave reason: click)
14:13:31 DEBUG    mouse      webview:_mousepress_opentarget:259 Middle click, setting target: ClickTarget.tab
14:13:31 DEBUG    webview    webpage:acceptNavigationRequest:565 acceptNavigationRequest, url file:///data/numbers/1.txt, type NavigationTypeLinkClicked, hint target ClickTarget.tab_bg, open_target ClickTarget.tab
14:13:31 DEBUG    webview    tabbedbrowser:tabopen:367 Creating new tab with URL PyQt5.QtCore.QUrl('file:///data/numbers/1.txt')
14:13:31 DEBUG    init       networkmanager:__init__:155 Initializing NetworkManager
14:13:31 DEBUG    init       networkmanager:__init__:160 NetworkManager init done
14:13:31 DEBUG    webview    tabbedbrowser:_get_new_tab_idx:426 new-tab-position right -> opening new tab at 1, next left: 0 / right: 2
14:13:31 DEBUG    webview    tabbedbrowser:on_title_changed:494 Changing title for idx 1 to 'file:///data/numbers/1.txt'
14:13:31 DEBUG    webview    browsertab:_set_load_status:532 load status for <qutebrowser.browser.webkit.webkittab.WebKitTab tab_id=1 url=''>: LoadStatus.loading
14:13:31 DEBUG    signals    signalfilter:_filter_signals:91 ignoring: cur_load_status_changed('loading') (tab 1)
14:13:31 DEBUG    signals    signalfilter:_filter_signals:91 ignoring: cur_load_started() (tab 1)
14:13:31 DEBUG    webview    webpage:on_stop_hinting:438 Finishing hinting.
14:13:31 ERROR    webview    webpage:_handle_errorpage:168 Error while loading file:///data/numbers/1.txt: Error opening /data/numbers/1.txt: No such file or directory
14:13:31 DEBUG    webview    webpage:_handle_errorpage:170 Error domain: 0, error code: 203
14:13:31 DEBUG    webview    browsertab:_set_load_status:532 load status for <qutebrowser.browser.webkit.webkittab.WebKitTab tab_id=1 url=''>: LoadStatus.loading
14:13:31 DEBUG    signals    signalfilter:_filter_signals:91 ignoring: cur_load_status_changed('loading') (tab 1)
14:13:31 DEBUG    signals    signalfilter:_filter_signals:91 ignoring: cur_load_started() (tab 1)
14:13:31 DEBUG    webview    tabbedbrowser:on_title_changed:494 Changing title for idx 1 to 'file:///data/numbers/1.txt'
14:13:31 DEBUG    signals    signalfilter:_filter_signals:91 ignoring: cur_url_changed(PyQt5.QtCore.QUrl('file:///data/numbers/1.txt')) (tab 1)
14:13:31 DEBUG    webview    tabbedbrowser:on_title_changed:486 Ignoring title change to ''.
14:13:31 DEBUG    webview    tabbedbrowser:on_title_changed:494 Changing title for idx 1 to 'Error loading page: file:///data/numbers/1.txt'
14:13:31 DEBUG    save       savemanager:mark_dirty:73 Marking history as dirty.
14:13:31 DEBUG    webview    browsertab:_set_load_status:532 load status for <qutebrowser.browser.webkit.webkittab.WebKitTab tab_id=1 url='file:///data/numbers/1.txt'>: LoadStatus.error
14:13:31 DEBUG    signals    signalfilter:_filter_signals:91 ignoring: cur_load_status_changed('error') (tab 1)
14:13:31 DEBUG    signals    signalfilter:_filter_signals:91 ignoring: cur_load_finished(False) (tab 1)
14:13:31 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: True
14:13:31 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.hint - delegating to <qutebrowser.keyinput.modeparsers.HintKeyParser supports_chains=True supports_count=False>
14:13:31 DEBUG    keyboard   basekeyparser:_debug_log:111 Got key: 0x1000000 / text: ''
14:13:31 DEBUG    keyboard   basekeyparser:_debug_log:111 Ignoring, no text char
14:13:31 DEBUG    keyboard   modeparsers:_handle_special_key:169 Got special key 0x1000000 text 
14:13:31 DEBUG    modes      modeman:leave:284 Leaving mode KeyMode.hint (reason: all filtered)
14:13:31 DEBUG    hints      hints:_cleanup:184 Disconnecting frame <PyQt5.QtWebKitWidgets.QWebFrame object at 0x7f385dcb9948>
14:13:31 DEBUG    hints      hints:_cleanup:198 Disconnected.
14:13:31 DEBUG    statusbar  text:maybe_reset_text:68 Resetting: 'Follow hint in background tab (rapid mode)...'
14:13:31 DEBUG    statusbar  text:set_text:55 Setting normal text to ''.
14:13:31 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: True, forward-unbound-keys: auto, passthrough: False, is_non_alnum: False --> filter: True (focused: <qutebrowser.browser.webkit.webview.WebView tab_id=0 url='file:///home/florian/proj/qutebrowser/git/tests/end2end/data/hints/number.html'>)
14:13:31 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: True
14:13:32 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.normal - delegating to <qutebrowser.keyinput.modeparsers.NormalKeyParser>
14:13:32 DEBUG    keyboard   basekeyparser:_debug_log:111 No binding found for ;.
14:13:32 DEBUG    keyboard   basekeyparser:_debug_log:111 Got key: 0x3b / text: ';'
14:13:32 DEBUG    keyboard   basekeyparser:_debug_log:111 No match for ';' (added ;)
14:13:32 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: True, forward-unbound-keys: auto, passthrough: False, is_non_alnum: False --> filter: True (focused: <qutebrowser.browser.webkit.webview.WebView tab_id=0 url='file:///home/florian/proj/qutebrowser/git/tests/end2end/data/hints/number.html'>)
14:13:32 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.normal - delegating to <qutebrowser.keyinput.modeparsers.NormalKeyParser>
14:13:32 DEBUG    keyboard   basekeyparser:_debug_log:111 No binding found for r.
14:13:32 DEBUG    keyboard   basekeyparser:_debug_log:111 Got key: 0x52 / text: 'r'
14:13:32 DEBUG    keyboard   basekeyparser:_debug_log:111 Definitive match for ';r'.
14:13:32 DEBUG    commands   command:run:508 command called: hint ['--rapid', 'links', 'tab-bg']
14:13:32 DEBUG    commands   command:run:523 Calling qutebrowser.browser.hints.HintManager.start(<qutebrowser.browser.hints.HintManager object at 0x7f38640be948>, True, <Group.links: 2>, <Target.tab_bg: 5>, win_id=0)
14:13:32 DEBUG    hints      hints:_init_elements:706 hints: 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10
14:13:32 DEBUG    message    message:set_text:363 Follow hint in background tab (rapid mode)...
14:13:32 DEBUG    statusbar  text:set_text:55 Setting normal text to 'Follow hint in background tab (rapid mode)...'.
14:13:32 DEBUG    hints      hints:_connect_frame_signals:668 Connecting frame <PyQt5.QtWebKitWidgets.QWebFrame object at 0x7f385dcb9948>
14:13:32 DEBUG    modes      modeman:enter:240 Entering mode KeyMode.hint (reason: HintManager.start)
14:13:32 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: True, forward-unbound-keys: auto, passthrough: False, is_non_alnum: False --> filter: True (focused: <qutebrowser.browser.webkit.webview.WebView tab_id=0 url='file:///home/florian/proj/qutebrowser/git/tests/end2end/data/hints/number.html'>)
14:13:32 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: True
14:13:32 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: True
14:13:33 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.hint - delegating to <qutebrowser.keyinput.modeparsers.HintKeyParser supports_chains=True supports_count=False>
14:13:33 DEBUG    keyboard   basekeyparser:_debug_log:111 Got key: 0x30 / text: '0'
14:13:33 DEBUG    keyboard   basekeyparser:_debug_log:111 No match for '0' (added 0)
14:13:33 DEBUG    hints      hints:handle_partial_key:874 Handling new keystring: '0'
14:13:33 DEBUG    modes      modeman:_eventFilter_keypress:194 handled: True, forward-unbound-keys: auto, passthrough: False, is_non_alnum: False --> filter: True (focused: <qutebrowser.browser.webkit.webview.WebView tab_id=0 url='file:///home/florian/proj/qutebrowser/git/tests/end2end/data/hints/number.html'>)
14:13:33 DEBUG    modes      modeman:_eventFilter_keyrelease:214 filter: True
14:13:33 DEBUG    modes      modeman:_eventFilter_keypress:169 got keypress in mode KeyMode.hint - delegating to <qutebrowser.keyinput.modeparsers.HintKeyParser supports_chains=True supports_count=False>
14:13:33 DEBUG    keyboard   basekeyparser:_debug_log:111 Got key: 0x30 / text: '0'
14:13:33 DEBUG    keyboard   basekeyparser:_debug_log:111 Definitive match for '00'.
14:13:33 DEBUG    modes      modeman:leave:284 Leaving mode KeyMode.hint (reason: all filtered)
14:13:33 DEBUG    hints      hints:_cleanup:184 Disconnecting frame <PyQt5.QtWebKitWidgets.QWebFrame object at 0x7f385dcb9948>
14:13:33 DEBUG    hints      hints:_cleanup:198 Disconnected.
14:13:33 DEBUG    statusbar  text:maybe_reset_text:68 Resetting: 'Follow hint in background tab (rapid mode)...'
14:13:33 DEBUG    statusbar  text:set_text:55 Setting normal text to ''.
14:13:33 ERROR    misc       crashsignal:exception_hook:211 Uncaught exception
Traceback (most recent call last):
  File "/home/florian/proj/qutebrowser/git/qutebrowser/app.py", line 862, in eventFilter
    return handler(event)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/app.py", line 822, in _handle_key_event
    return man.eventFilter(event)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/modeman.py", line 318, in eventFilter
    return self._eventFilter_keypress(event)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/modeman.py", line 170, in _eventFilter_keypress
    handled = parser.handle(event)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/modeparsers.py", line 211, in handle
    match = self._handle_single_key(e)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/basekeyparser.py", line 197, in _handle_single_key
    self.execute(binding, self.Type.chain, count)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/modeparsers.py", line 234, in execute
    hintmanager.fire(cmdstr)
  File "/home/florian/proj/qutebrowser/git/qutebrowser/browser/hints.py", line 1044, in fire
    for string, elem in self._context.elems.items():
AttributeError: 'NoneType' object has no attribute 'elems'
```



Discussion:

Resolving patch:
diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py
--- a/qutebrowser/browser/hints.py
+++ b/qutebrowser/browser/hints.py
@@ -201,6 +201,7 @@ def _cleanup(self):
                                     window=self._win_id)
         message_bridge.maybe_reset_text(text)
         self._context = None
+        self._filterstr = None
 
     def _hint_strings(self, elems):
         """Calculate the hint strings for elems.


Test patch: