# Buggy code
def __init__(self, master):
    self.master = master
    low, high = [], []
    for k, v in palettes.palettes.items():
        if v.high:
            high.append(k)
        else:
            low.append(k)
    high.sort()
    low.sort()

    options = [select.Heading("High Colour")]

    def mkopt(name):
        return select.Option(
            i,
            None,
            lambda: self.master.options.console_palette == name,
            lambda: setattr(self.master.options, "palette", name),
        )

    for i in high:
        options.append(mkopt(i))
    options.append(select.Heading("Low Colour"))
    for i in low:
        options.append(mkopt(i))

    options.extend(
        [
            select.Heading("Options"),
            select.Option(
                "Transparent",
                "T",
                lambda: master.options.console_palette_transparent,
                master.options.toggler("palette_transparent"),
            ),
        ]
    )

    self.lb = select.Select(options)
    title = urwid.Text("Palettes")
    title = urwid.Padding(title, align="left", width=("relative", 100))
    title = urwid.AttrWrap(title, "heading")
    self._w = urwid.Frame(self.lb, header=title)
    master.options.changed.connect(self.sig_options_changed)


# Traceback (KeyError)
Traceback (most recent call last):
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/master.py", line 281, in run
self.loop.run()
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 278, in run
self._run()
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 376, in _run
self.event_loop.run()
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 682, in run
self._loop()
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 719, in _loop
self._watch_files[fd]()
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/raw_display.py", line 393, in <lambda>
event_loop, callback, self.get_available_raw_input())
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/raw_display.py", line 493, in parse_input
callback(processed, processed_codes)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 403, in _update
self.process_input(keys)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 503, in process_input
k = self._topmost_widget.keypress(self.screen_size, k)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/window.py", line 84, in keypress
k = super().keypress(size, k)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/container.py", line 1128, in keypress
return self.body.keypress( (maxcol, remaining), key )
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/urwid/container.py", line 1128, in keypress
return self.body.keypress( (maxcol, remaining), key )
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/select.py", line 114, in keypress
self.get_focus()[0].option.activate()
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/tools/console/palettepicker.py", line 46, in <lambda>
lambda: setattr(self.master.options, "palette", name)
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/optmanager.py", line 114, in __setattr__
self.update(**{attr: value})
File "/usr/local/Cellar/mitmproxy/2.0.0/libexec/lib/python3.6/site-packages/mitmproxy/optmanager.py", line 141, in update
raise KeyError("No such option: %s" % k)
KeyError: 'No such option: palette'

# Fixed code
def __init__(self, master):
    self.master = master
    low, high = [], []
    for k, v in palettes.palettes.items():
        if v.high:
            high.append(k)
        else:
            low.append(k)
    high.sort()
    low.sort()

    options = [select.Heading("High Colour")]

    def mkopt(name):
        return select.Option(
            i,
            None,
            lambda: self.master.options.console_palette == name,
            lambda: setattr(self.master.options, "console_palette", name),
        )

    for i in high:
        options.append(mkopt(i))
    options.append(select.Heading("Low Colour"))
    for i in low:
        options.append(mkopt(i))

    options.extend(
        [
            select.Heading("Options"),
            select.Option(
                "Transparent",
                "T",
                lambda: master.options.console_palette_transparent,
                master.options.toggler("console_palette_transparent"),
            ),
        ]
    )

    self.lb = select.Select(options)
    title = urwid.Text("Palettes")
    title = urwid.Padding(title, align="left", width=("relative", 100))
    title = urwid.AttrWrap(title, "heading")
    self._w = urwid.Frame(self.lb, header=title)
    master.options.changed.connect(self.sig_options_changed)