[Datetime-SIG] Another round on error-checking

Alexander Belopolsky alexander.belopolsky at gmail.com
Mon Aug 31 20:26:15 CEST 2015


On Mon, Aug 31, 2015 at 1:58 PM, Tim Peters <tim.peters at gmail.com> wrote:

> PEP 495 specifies resolving such cases by magic, in essentially
> arbitrary (from the user's point of view) ways.  This isn't for
> backward compatibility, because 495-compliant tzinfos don't currently
> exist
>

.. but tzinfo.fromutc() [1] does exist and the first thing happening in
that code is an unguarded call to utcoffset() on a UTC datetime with a
transplanted tzinfo. [2]  A trick like this have been valid in datetime
since its introduction and has been used in numerous places since.   You
know that with a little effort universal .fromutc() can be rewritten to be
PEP 495 compliant.

If you think allowing datetime.utcoffset() to raise an exception is an
option, let's first see how one can rewrite universal tzinfo.fromutc() for
that design.  Even though I don't think reusing a universal .fromutc() is a
good option for tzinfo implementers, it gives an example of simple but
non-trivial datetime manipulation code which PEP 495 is designed not to
break.

[1]: https://hg.python.org/cpython/file/v3.5.0rc2/Lib/datetime.py#l957
[2]: https://hg.python.org/cpython/file/v3.5.0rc2/Lib/datetime.py#l965
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150831/1d7ca862/attachment-0001.html>


More information about the Datetime-SIG mailing list