# Buggy code
def get_dates(vevent, key):
    dates = vevent.get(key)
    if dates is None:
        return
    if not isinstance(dates, list):
        dates = [dates]

    dates = (leaf.dt for tree in dates for leaf in tree.dts)
    dates = localize_strip_tz(dates, events_tz)
    return map(sanitize_datetime, dates)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/ui/__init__.py", line 1296, in start_pane
loop.run()
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 278, in run
self._run()
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 376, in _run
self.event_loop.run()
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 682, in run
self._loop()
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 719, in _loop
self._watch_files[fd]()
File "/usr/local/Cellar/khal/0.9.5/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/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/raw_display.py", line 493, in parse_input
callback(processed, processed_codes)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 403, in _update
self.process_input(keys)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 509, in process_input
something_handled |= bool(self.unhandled_input(k))
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/urwid/main_loop.py", line 555, in unhandled_input
return self._unhandled_input(input)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/ui/base.py", line 162, in on_key_press
self.backtrack()
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/ui/base.py", line 147, in backtrack
cb(data)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/ui/__init__.py", line 1095, in cleanup
event.delete_instance(rec_id)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/khalendar/event.py", line 602, in delete_instance
delete_instance(self._vevents['PROTO'], instance)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/khalendar/utils.py", line 327, in delete_instance
_add_exdate(vevent, instance)
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/khalendar/utils.py", line 292, in _add_exdate
exdates.append(dates_from_exdate(vddlist))
File "/usr/local/Cellar/khal/0.9.5/libexec/lib/python3.6/site-packages/khal/khalendar/utils.py", line 282, in dates_from_exdate
return [dts.dt for dts in vevent['EXDATE'].dts]
AttributeError: 'list' object has no attribute 'dts'

# Fixed code
def get_dates(vevent, key):
    # TODO replace with get_all_properties
    dates = vevent.get(key)
    if dates is None:
        return
    if not isinstance(dates, list):
        dates = [dates]

    dates = (leaf.dt for tree in dates for leaf in tree.dts)
    dates = localize_strip_tz(dates, events_tz)
    return map(sanitize_datetime, dates)