This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add datetime.fromisocalendar
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, eamanu, lemburg, matrixise, p-ganssle, vstinner
Priority: low Keywords: patch

Created on 2019-02-15 14:28 by p-ganssle, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11888 merged p-ganssle, 2019-02-16 00:08
Messages (7)
msg335616 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2019-02-15 14:28
Datetime has many methods that "serializes" an instance to some other format - toordinal, timestamp, isoformat, etc. Most methods that "serialize" a datetime have a corresponding method that "deserializes" that method, or another way to reverse the operation:

- strftime / strptime
- timestamp / fromtimestamp
- isoformat / fromisoformat
- toordinal / fromordinal
- timetuple / datetime(*thetuple[0:6])

However, as I found out when implementing `dateutil.parser.isoparse`, there is no simple way to invert `isocalendar()`.

I have an implementation as part of dateutil.parser.isoparse:

https://github.com/dateutil/dateutil/blob/master/dateutil/parser/isoparser.py#L297

If there are no objections, I'd like to add an implementation in CPython itself. Thinking the name should be `fromisocalendar`.
msg335617 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-02-15 14:31
+1
msg335641 - (view) Author: Emmanuel Arias (eamanu) * Date: 2019-02-15 19:19
+1
msg335661 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2019-02-16 00:15
I have a first-pass PR, a few questions to address:


1. Should it take three arguments or a single 3-tuple? (I've gone with 3 arguments)
2. Since all three arguments are required, should we make them positional-only?
3. Should we allow time components in the `datetime` flavor of this? If so, I think we would also want datetime.isocalendar() to return a longer tuple, which would be backwards incompatible.
4. Should we add a `tz` argument in the datetime flavor?

I think for questions 3 and 4 the answer is no, modelling after .toordinal/.fromordinal.
msg335783 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2019-02-17 18:07
The attached PR is more or less fully ready, I think the correct answers to 1, 3 and 4 are that we should go with 3 separate arguments and we should not allow either time components or tz components, at least in this version.

In the future, I don't think it will be backwards incompatible to add in these features if they are desired (though I imagine they won't be terribly in demand, and it's pretty easy to work around).

The only real remaining question is number 2. Right now I am allowing keyword arguments, but the only real value I see in doing that is that PEP 570 (positional-only parameters) is not done yet and it's kind of annoying to implement "positional only parameters" in the pure Python version. If anyone feels strongly about this, let me know, otherwise I'll switch the implementation over to positional-only parameters.
msg341079 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-04-29 13:22
New changeset 88c093705615c50c47fdd9ab976803f73de7e308 by Victor Stinner (Paul Ganssle) in branch 'master':
bpo-36004: Add date.fromisocalendar (GH-11888)
https://github.com/python/cpython/commit/88c093705615c50c47fdd9ab976803f73de7e308
msg341080 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-04-29 13:31
Thanks Paul, nice enhancement!
History
Date User Action Args
2022-04-11 14:59:11adminsetgithub: 80185
2019-04-29 13:31:05vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg341080

stage: patch review -> resolved
2019-04-29 13:22:06vstinnersetnosy: + vstinner
messages: + msg341079
2019-02-17 18:07:49p-gansslesetmessages: + msg335783
2019-02-16 00:15:42p-gansslesetmessages: + msg335661
2019-02-16 00:08:41p-gansslesetkeywords: + patch
stage: patch review
pull_requests: + pull_request11918
2019-02-15 19:19:43eamanusetnosy: + eamanu
messages: + msg335641
2019-02-15 14:31:05matrixisesetnosy: + matrixise
messages: + msg335617
2019-02-15 14:28:36p-gansslecreate