Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db51920

Browse files
committed
Time2Internaldate(): Call isinstance() once for each of the type tests
instead of possibly twice by using a sequence of types to check for. Add a message to the ValueError that can be raised.
1 parent 1e2fb57 commit db51920

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Lib/imaplib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,14 +1069,14 @@ def Time2Internaldate(date_time):
10691069
Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'
10701070
"""
10711071

1072-
if isinstance(date_time, int) or isinstance(date_time, float):
1072+
if isinstance(date_time, (int, float)):
10731073
tt = time.localtime(date_time)
1074-
elif isinstance(date_time, tuple) or \
1075-
isinstance(date_time, time.struct_time):
1074+
elif isinstance(date_time, (tuple, time.struct_time)):
10761075
tt = date_time
10771076
elif isinstance(date_time, str):
10781077
return date_time # Assume in correct format
1079-
else: raise ValueError
1078+
else:
1079+
raise ValueError("date_time not of a known type")
10801080

10811081
dt = time.strftime("%d-%b-%Y %H:%M:%S", tt)
10821082
if dt[0] == '0':

0 commit comments

Comments
 (0)