[Python-Dev] basenumber redux
"Martin v. Löwis"
martin at v.loewis.de
Wed Jan 18 00:21:13 CET 2006
Alex Martelli wrote:
> But this doesn't apply to the Python Standard Library, for example see
> line 1348 of imaplib.py: "if isinstance(date_time, (int, float)):".
[...]
> Being able to change imaplib to use basenumber instead of (int, float)
> won't make it SIMPLER, but it will surely make it BETTER -- why should
> a long be rejected, or a Decimal, for that matter?
Right. I think this function should read
if isinstance(date_time, str) and \
(date_time[0],date_time[-1]) == ('"','"'):
return date_time # Assume in correct format
if isinstance(date_time, (tuple, time.struct_time)):
tt = date_time
else:
tt = time.localtime(date_time)
If this is something that time.localtime can't handle, it will
give a TypeError. This is much better than
raise ValueError("date_time not of a known type")
# (why does it raise a ValueError if it says "type"?)
Regards,
Martin
More information about the Python-Dev
mailing list