New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-24416: Return a IsoCalendarDate from date.isocalendar() #15633
Conversation
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
@taleinat @ZackerySpytz cc @pganssle @abalkin First of all, thanks for the code review. However, other comments have been raised by the core developer on whether this patch is acceptable. Again, thank you for the code reviews. :) |
@rhettinger |
I haven't had time to do a full review yet, but I've added one comment about refactoring a test (feel free to dispute that if you disagree), and I do think that we should make the particular class used a private implementation detail and not expose it, per my comment here.
@taleinat I know that you asked for IsoCalendarDate
to be documented - are you OK with us only guaranteeing that the return value has year
, week
and day
fields but not exposing the actual class for isinstance
or construction purposes? If so, I think we can just document those properties in the isocalendar()
documentation.
Marking this as closed. See the discussion on BPO where we've decided that collections.namedtuple() wasn't the way to go here. Instead, C functions should use structseq. Thanks for PR and sorry the effort didn't come to fruition. |
@rhettinger This PR uses a structseq, it's what we used for the benchmarks, and I see no reason to close it. Dong-Hee can just push more commits with any changes you might request. I'm going to re-open this, since @taleinat and I already have review comments on it and it's unclear what you would want @corona10 to do differently here (and even so, comments and pushing new commits would probably be preferable to closing it and opening a new PR). |
I changed the title to replace "named tuple" with "structseq". All the code and doc changes checked in here should do something similar - the correct name is "struct sequence" (see, e.g., the existing docs for |
Paul, are you still wanting to go down the path of using collections.namedtuple() instead of structseq? If not, this PR needs to be closed. |
Raymond, the actual current code here uses |
I had make a quick scan of the latest version and didn't expect to see |
Yes, the Python and C implementations differ in the current state. I just assumed Paul was keen to change the C version to structseqs first, to get his benchmarks done. |
Also, I had thought we were going to use "named tuple" (two words) to cover the generic concept including both collections.namedtuple() and structseq. See https://docs.python.org/3/glossary.html#term-named-tuple I don't think the user ever sees something called a "structseq".
I don't think the API of a structseq is publicly documented anywhere, so it may not make sense to refer to it at all. For example, see what was done for https://docs.python.org/3/library/time.html#time.struct_time |
In order to leave IsocalendarDate as a private class and to improve what backwards compatibility is offered for pickling the result of a datetime.isocalendar() call, add a __reduce__ method to the named tuples that reduces them to plain tuples. Also add a test to this effect.
This reverts commit 448a2109dfde1558a082de78171d17580995a950.
This reverts commit 104264121ea49795da87fc803a270bdda8fa21d2.
I have made the requested changes; please review again |
cc @vstinner |
@@ -1210,6 +1210,36 @@ def __reduce__(self): | |||
else: | |||
return (self.__class__, args, state) | |||
|
|||
|
|||
class IsoCalendarDate(tuple): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__slots__ = () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pppery Can you explain the reason about this suggestion?
@corona10 Hey, sorry I never got back to this, I've been swamped with PEP 615, but I'd love to get this in before the feature freeze. Do you mind letting me know the current state of things? Do you have a recommendation between this implementation and the other one? I'm also increasingly amenable to the idea of just having this thing named |
Hmm, I should remember what I tried before for this issue :) AFAIK(??) I still prefer the current PR implementation. But if you decide specific requirements then we can change the implementation. |
or we have to think that this issue is should be solved? |
https://bugs.python.org/issue24416