This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients belopolsky
Date 2018-06-09.00:08:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1528502888.29.0.592728768989.issue33812@psf.upfronthosting.co.za>
In-reply-to
Content
Consider the following code:

$ cat bug.py
import sys
if len(sys.argv) > 1:
    sys.modules['_datetime'] = None
from datetime import tzinfo, datetime, timezone

class TZ(tzinfo):
    def utcoffset(self, t):
        pass

print(datetime(2000,1,1,tzinfo=TZ()).astimezone(timezone.utc))

When running with no arguments (with C acceleration), I get

$ ./python.exe bug.py
2000-01-01 00:00:00+00:00

but the pure python code produces an error

$ ./python.exe bug.py pure
Traceback (most recent call last):
  File "bug.py", line 10, in <module>
    print(datetime(2000,1,1,tzinfo=TZ()).astimezone(timezone.utc))
  File ".../Lib/datetime.py", line 1783, in astimezone
    raise ValueError("astimezone() requires an aware datetime")
ValueError: astimezone() requires an aware datetime

Note that some kind of error is expected because TZ.utcoffset() returns None instead of a timedelta, but the error message produced by pure python code is confusing.
History
Date User Action Args
2018-06-09 00:08:08belopolskysetrecipients: + belopolsky
2018-06-09 00:08:08belopolskysetmessageid: <1528502888.29.0.592728768989.issue33812@psf.upfronthosting.co.za>
2018-06-09 00:08:08belopolskylinkissue33812 messages
2018-06-09 00:08:05belopolskycreate