> -----Original Message----- > From: Python-Dev [mailto:python-dev-bounces+tritium- > list=sdamon....@python.org] On Behalf Of Alexander Belopolsky > Sent: Tuesday, October 24, 2017 5:54 PM > To: Chris Barker <chris.bar...@noaa.gov> > Cc: Python-Dev <python-dev@python.org> > Subject: Re: [Python-Dev] iso8601 parsing > > On Tue, Oct 24, 2017 at 5:26 PM, Chris Barker <chris.bar...@noaa.gov> > wrote: > > On Mon, Oct 23, 2017 at 5:33 PM, Hasan Diwan <hasan.di...@gmail.com> > wrote: > >> > > 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 fitting. 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. $0.02 > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/tritium- > list%40sdamon.com _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com