Keep type() instead of isinstance() for some cases

Since isinstance() deals with inheritance and `datetime.datetime` inherits
from `datetime.date` we have no way to distinguish the object type.
pull/25/head
Pablo Castellano 2018-09-17 00:29:49 +02:00
rodzic e3b3356105
commit 682dbe2ff5
1 zmienionych plików z 4 dodań i 4 usunięć

Wyświetl plik

@ -157,7 +157,7 @@ def create_event(component):
event.end = normalize(component.get('dtend').dt)
event.summary = str(component.get('summary'))
event.description = str(component.get('description'))
event.all_day = isinstance(component.get('dtstart').dt, date)
event.all_day = type(component.get('dtstart').dt) is date
return event
@ -169,10 +169,10 @@ def normalize(dt):
:param dt: date to normalize
:return: date as datetime with timezone
"""
if isinstance(dt, datetime):
pass
elif isinstance(dt, date):
if type(dt) is date:
dt = datetime(dt.year, dt.month, dt.day, 0, 0)
elif type(dt) is datetime:
pass
else:
raise ValueError("unknown type %s" % type(dt))