# Buggy code
def fromVEvents(cls, events_list, ref=None, **kwargs):
    """
    :type events: list
    """
    assert isinstance(events_list, list)

    vevents = dict()
    if len(events_list) == 1:
        vevents["PROTO"] = events_list[0]  # TODO set mutable = False
    else:
        for event in events_list:
            if "RECURRENCE-ID" in event:
                if invalid_timezone(event["RECURRENCE-ID"]):
                    default_timezone = kwargs["locale"]["default_timezone"]
                    recur_id = default_timezone.localize(event["RECURRENCE-ID"].dt)
                    ident = str(to_unix_time(recur_id))
                else:
                    ident = str(to_unix_time(event["RECURRENCE-ID"].dt))
                vevents[ident] = event
            else:
                vevents["PROTO"] = event
    if ref is None:
        ref = "PROTO"

    try:
        if type(vevents[ref]["DTSTART"].dt) != type(vevents[ref]["DTEND"].dt):  # flake8: noqa
            raise ValueError(
                "DTSTART and DTEND should be of the same type (datetime or date)"
            )
    except KeyError:
        pass

    instcls = cls._get_type_from_vDDD(vevents[ref]["DTSTART"])
    return instcls(vevents, ref=ref, **kwargs)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/local/bin/khal", line 9, in <module>
load_entry_point('khal==0.7.0', 'console_scripts', 'khal')()
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 696, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 1037, in invoke
return Command.invoke(self, ctx)
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/khal/cli.py", line 226, in cli
ctx.invoke(cli.commands[command])
File "/usr/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/khal/cli.py", line 254, in calendar
full=full
File "/usr/local/lib/python2.7/site-packages/khal/controllers.py", line 149, in calendar
show_all_days=show_all_days, full=full, **kwargs)
File "/usr/local/lib/python2.7/site-packages/khal/controllers.py", line 122, in get_agenda
items = event.relative_to(day, full).splitlines()
File "/usr/local/lib/python2.7/site-packages/khal/khalendar/event.py", line 374, in relative_to
if self.start_local < day_start:
File "/usr/local/lib/python2.7/site-packages/khal/khalendar/event.py", line 486, in start_local
return self.start.astimezone(self._locale['local_timezone'])
File "/usr/local/lib/python2.7/site-packages/khal/khalendar/event.py", line 473, in start
return self._locale['default_timezone'].localize(self._start)
File "/usr/lib/python2.7/site-packages/pytz/tzinfo.py", line 303, in localize
if dt.tzinfo is not None:
AttributeError: 'datetime.date' object has no attribute 'tzinfo'

# Fixed code
def fromVEvents(cls, events_list, ref=None, **kwargs):
    """
    :type events: list
    """
    assert isinstance(events_list, list)

    vevents = dict()
    if len(events_list) == 1:
        vevents["PROTO"] = events_list[0]  # TODO set mutable = False
    else:
        for event in events_list:
            if "RECURRENCE-ID" in event:
                if invalid_timezone(event["RECURRENCE-ID"]):
                    default_timezone = kwargs["locale"]["default_timezone"]
                    recur_id = default_timezone.localize(event["RECURRENCE-ID"].dt)
                    ident = str(to_unix_time(recur_id))
                else:
                    ident = str(to_unix_time(event["RECURRENCE-ID"].dt))
                vevents[ident] = event
            else:
                vevents["PROTO"] = event
    if ref is None:
        ref = "PROTO"

    try:
        if type(vevents[ref]["DTSTART"].dt) != type(vevents[ref]["DTEND"].dt):  # flake8: noqa
            raise ValueError(
                "DTSTART and DTEND should be of the same type (datetime or date)"
            )
    except KeyError:
        pass

    if kwargs.get("start"):
        instcls = cls._get_type_from_date(kwargs.get("start"))
    else:
        instcls = cls._get_type_from_vDDD(vevents[ref]["DTSTART"])
    return instcls(vevents, ref=ref, **kwargs)