[Python-Dev] iso8601 parsing
tritium-list at sdamon.com
Wed Oct 25 11:45:15 EDT 2017
> -----Original Message-----
> From: Python-Dev [mailto:python-dev-bounces+tritium-
> list=sdamon.com at python.org] On Behalf Of Alexander Belopolsky
> Sent: Tuesday, October 24, 2017 5:54 PM
> To: Chris Barker <chris.barker at noaa.gov>
> Cc: Python-Dev <python-dev at python.org>
> Subject: Re: [Python-Dev] iso8601 parsing
> On Tue, Oct 24, 2017 at 5:26 PM, Chris Barker <chris.barker at noaa.gov>
> > On Mon, Oct 23, 2017 at 5:33 PM, Hasan Diwan <hasan.diwan at gmail.com>
> > can anyone argue that it's not a good idea for datetime ot
> > be able to read the iso format it puts out?
> No, but the last time I suggested that that datetime types should
> satisfy the same invariants as numbers, namely
> T(repr(x)) == x, the idea was met will silence. I, on the other hand,
> am not very enthusiastic about named constructors such as
> date.isoparse(). Compared with date(s:str), this is one more method
> name to remember, plus the potential for abuse as an instance method.
> What is d.isoparse('2017-11-24')?
Datetime.datetime.fromiso() (classmethod) is much more in keeping with the
rest of the datetime api - in fact, I have tried calling that method more
than once, before remembering datetime *doesn't* have that classmethod.
Making it a classmethod solves any concerns about calling it as an instance
method (the same way d.now() and d.strptime() just create and return a new
datetime objects, not mutates the current). In fact, looking at the docs,
most of the methods are classmethods, so an additional classmethod is
I really do not like the idea of making the first positional argument of the
datetime constructor int or str. What happens when you pass a string for
the first argument and ints for subsequent arguments? You would have to
raise a typeerror or valueerror. I don't like that API design - it means
the type of the first argument changes the semantic meaning of subsequent
arguments, and that just adds a level of confusion to any api. You might be
able to get away with that in third party code, but this is the standard
library, and this is the time manipulation module in the standard library -
you have to assume that this is one of the first modules a new user uses, we
have to keep the api sane.
The only way I can think of keeping the api sane and still pass an iso
string to the constructor is to pass It as a keyword argument - and at that
point you have to remember the argument name anyways, so you might as well
make it a classmethod to match everything else in the library.
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/tritium-
More information about the Python-Dev