On Wed, Oct 25, 2017 at 4:22 PM, Alexander Belopolsky < firstname.lastname@example.org> wrote:
times. The only difference is that instead of calling the type directly, you call the appropriate classmethod.
What am I missing?
Nothing. The only annoyance is that the data processing code typically needs to know the type anyway, so the classmethod is one more variable to keep track of.
I don't think anyone is arguing that is is hard to do either way, or that hard to use either way.
I think it comes down to a trade-off between:
Having an API for datetime that is like the datetime for number types:
int(str(an_int)) == an_int
datetime(str(a_datetime)) == a_datetime
Alexander strongly supports that.
Or an API that is perhaps more like the rest of the datetime api, which has a number of alternate constructors:
would make a lot of sense.
I would note that the number types don't have all those alternate constructors Also, the number types mostly have a single parameter (except int has an optional base parameter). So I'm not sure the parallel is that strong.
Would it be horrible if we did both?
After all, right now, datetime has:
In : dt.isoformat() Out: '2017-10-25T16:30:48.744489'
and In : dt.__str__() Out: '2017-10-25 16:30:48.744489'
which do almost the same thing (I understand the "T" is option in iso 8601)
However, maybe they are different when you add a time zone?
ISO 8601 support offsets, but not time zones -- presumably the __str__ supports the full datetime tzinfo somehow. Which may be why .isoformat() exists.
Though I don't think that means you couldn't have the __init__ parse proper ISO strings, in addition to the full datetime __str__ results.