[Datetime-SIG] Strict Invalid Time Checking: an idea for another PEP

Alexander Belopolsky alexander.belopolsky at gmail.com
Wed Aug 26 01:16:01 CEST 2015

Here is an outline of a "Strict Invalid Time Checking" that might work: the
values of datetime.fold attribute will be restricted to 0 and 1, but the
datetime constructor will accept None as a possible value of the fold
argument.  The datetime constructor that receives fold=None will set
self.fold both ways and call self.tzinfo.utcoffset(self) twice before
returning the constructed instance.  If the values returned by the two
utcoffset() calls match - an instance with self.fold=0 will be returned, if
not - they will be compared and an appropriate error returned.

This design seems workable, but immediately raises a question: shouldn't
datetime constructor get the strict=False argument instead of encoding it
in the third value of fold?

And if we want to have datetime(..., strict=True), why not just have
strict_datetime(...) function in your toolkit or on PyPI?  Not every 8-line
function need to be in the standard library.

We can discuss this and other questions if someone decides to champion
a Strict Invalid Time Checking PEP after PEP 495 is in-place.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150825/a4d643b0/attachment.html>

More information about the Datetime-SIG mailing list