[Python-ideas] Making datetime __str__ and isoformat more consistent

Andrew Barnert abarnert at yahoo.com
Sat Nov 2 02:52:43 CET 2013


On Nov 1, 2013, at 17:36, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:

> 
> On Fri, Nov 1, 2013 at 8:28 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
>> What about just adding a fromisoformat classmethod constructor that's meant specifically for round tripping isoformat?
> 
> What about following the lead of int(), float(), etc. and allow datetime() take a single string argument? 

I have three (not entirely separate) concerns.

The first is that this would imply that ISO is _the_ format for datetimes, rather than just _a_ format. If you ask a normal person for an integer, unless he's got the Super Bowl in the brain, int will parse his input. Ask him for a date, and it's very unlikely it'll be in ISO format.

The second problem is false positives. "2003" is a valid ISO date string, equivalent to "20030101" or "20030101T00:00:00". But in most contexts you wouldn't want that interpreted as a valid date or datetime. John Nagle's comment on the tracker (http://bugs.python.org/issue15873#msg169966) explains a similar concern.

Finally, I'd be happy with a fromisoformat that _only_ handled the output from the isoformat function, but a general constructor would seem incomplete unless it handled all of ISO 8601, or at least all of RFC 3339. That isn't exactly _hard_ (the RFC was meant to be implementable, after all), but it's a higher bar than needed for the problem that started this thread.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131101/174f7032/attachment.html>


More information about the Python-ideas mailing list