Hi,
I use datetime.date.isocalendar()
a lot and I was wondering why it’s return type (IsoCalendarDate
) wasn’t part of datetime
public API?
I missed it a few times when typing functions using ISO week-numbering dates as input / output, for example
def format_iso_date(iso_date: datetime.IsoCalendarDate) -> str: # invalid type
return f"{iso_date.year:04}-W{iso_date.week:02}-{iso_date.weekday}"
which seems a pretty fair use case to me. I could of course pass datetime
objects and call isocalendar()
inside the function, but I’d rater not to avoid multipe conversions.
I suppose this class is directly implemented in C if the module is installed, without Python interface so it we can’t make it instanciable, but maybe it could be available only for typing? While not really useful before 3.9 (when isocalendar()
returned a tuple and not a namedtuple), I think could be now.
Thanks!