Repository: mitmproxy/mitmproxy

Issue:
Crash when editing str-options
##### Steps to reproduce the problem:

1. Start `mitmproxy` in interactive mode
2. Type `O` to switch to the options view
3. Edit a random `str`-option
4. See `mitmproxy` crash with the following stacktrace:
```
Traceback (most recent call last):
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/mitmproxy/master.py", line 86, in run_loop
    loop()
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/urwid/main_loop.py", line 286, in run
    self._run()
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/urwid/main_loop.py", line 384, in _run
    self.event_loop.run()
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/urwid/main_loop.py", line 1484, in run
    reraise(*exc_info)
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/urwid/compat.py", line 58, in reraise
    raise value
  File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/urwid/raw_display.py", line 404, in <lambda>
    event_loop, callback, self.get_available_raw_input())
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/urwid/raw_display.py", line 502, in parse_input
    callback(processed, processed_codes)
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/urwid/main_loop.py", line 411, in _update
    self.process_input(keys)
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/urwid/main_loop.py", line 511, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/mitmproxy/tools/console/window.py", line 309, in keypress
    k = super().keypress(size, k)
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/urwid/container.py", line 1131, in keypress
    return self.body.keypress( (maxcol, remaining), key )
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/mitmproxy/tools/console/window.py", line 44, in keypress
    ret = super().keypress(size, key)
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/urwid/container.py", line 1131, in keypress
    return self.body.keypress( (maxcol, remaining), key )
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/mitmproxy/tools/console/options.py", line 283, in keypress
    return self.focus_item.keypress(tsize, key)
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/mitmproxy/tools/console/options.py", line 177, in keypress
    d = self.master.options.parse_setval(foc.opt.name, v)
  File "/tmp/mitmproxy-crash/lib/python3.6/site-packages/mitmproxy/optmanager.py", line 332, in parse_setval
    if o.typespec in (str, typing.Optional[str]):
AttributeError: 'str' object has no attribute 'typespec'

mitmproxy has crashed!
Please lodge a bug report at:
        https://github.com/mitmproxy/mitmproxy
```



##### System information

```
Mitmproxy: 4.0.3
Python:    3.6.6
OpenSSL:   OpenSSL 1.1.0h  27 Mar 2018
Platform:  Linux-4.17.0-x86_64-with-debian-buster-sid
```


Discussion:

Resolving patch:
diff --git a/mitmproxy/tools/console/options.py b/mitmproxy/tools/console/options.py
--- a/mitmproxy/tools/console/options.py
+++ b/mitmproxy/tools/console/options.py
@@ -174,7 +174,7 @@ def keypress(self, size, key):
                 foc, idx = self.get_focus()
                 v = self.walker.get_edit_text()
                 try:
-                    d = self.master.options.parse_setval(foc.opt.name, v)
+                    d = self.master.options.parse_setval(foc.opt, v)
                     self.master.options.update(**{foc.opt.name: d})
                 except exceptions.OptionsError as v:
                     signals.status_message.send(message=str(v))


Test patch: