classification
Title: When tzinfo.utcoffset is out-of-bounds, the exception message is misleading
Type: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: belopolsky Nosy List: belopolsky, exarkun, lemburg
Priority: normal Keywords:

Created on 2011-12-08 17:23 by exarkun, last changed 2012-06-22 17:39 by belopolsky. This issue is now closed.

Messages (4)
msg149046 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2011-12-08 17:23
When a timezone produces an out-of-bounds utc offset, the resulting exception always claims that the offset was 1440, rather than whatever it was.  Example:

from datetime import timedelta, datetime, tzinfo

class X(tzinfo):
    def utcoffset(self, time):
        return timedelta(days=2)

datetime.now(tz=X())
msg150584 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2012-01-04 03:51
Is 3.3 message better?

>>> datetime.now(tz=X())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: offset must be a timedelta strictly between -timedelta(hours=24) and timedelta(hours=24).

In 2.7, the message is indeed misleading:

>>> datetime.now(tz=X())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: tzinfo.utcoffset() returned 1440; must be in -1439 .. 1439

I am not sure fixing this in 2.x is worth the trouble, but I would consider improving the message in 3.x by adding information about the actual offset.  I vaguely remember that there was a reason for leaving that info out in 3.x.
msg162730 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2012-06-13 21:38
Does anyone still care about this issue? I think the error message in 3.2 is good enough and fixing this in 2.x is not worth the trouble.  I am inclined to close this as "won't fix".
msg163445 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2012-06-22 17:39
Fixed in changeset a7237f157625.
History
Date User Action Args
2012-06-22 17:39:44belopolskysetstatus: open -> closed
resolution: fixed
messages: + msg163445

versions: - Python 2.7
2012-06-13 21:38:21belopolskysetmessages: + msg162730
versions: + Python 3.3, - Python 3.4
2012-01-04 03:51:30belopolskysetassignee: belopolsky
stage: needs patch
messages: + msg150584
versions: + Python 3.4
2012-01-04 03:39:19ned.deilysetnosy: + lemburg, belopolsky
2011-12-08 17:23:10exarkuncreate