Skip to content
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

Closed
wants to merge 20 commits into from

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Sep 1, 2019

@mangrisano
Copy link
Contributor

mangrisano commented Sep 1, 2019

/cc @abalkin @pganssle

Copy link
Contributor

@taleinat taleinat left a comment

In addition to the in-line comments, note also that the new IsoCalendarDate class needs its own (small) section in the docs.

Doc/library/datetime.rst Outdated Show resolved Hide resolved
Doc/whatsnew/3.9.rst Show resolved Hide resolved
Lib/datetime.py Outdated Show resolved Hide resolved
Lib/datetime.py Outdated Show resolved Hide resolved
Lib/test/datetimetester.py Show resolved Hide resolved
Doc/whatsnew/3.9.rst Show resolved Hide resolved
@bedevere-bot
Copy link

bedevere-bot commented Sep 1, 2019

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Modules/_datetimemodule.c Outdated Show resolved Hide resolved
Modules/_datetimemodule.c Outdated Show resolved Hide resolved
Modules/_datetimemodule.c Outdated Show resolved Hide resolved
@corona10 corona10 changed the title bpo-24416: Return a namedtuple from date.isocalendar() [WIP] bpo-24416: Return a namedtuple from date.isocalendar() Sep 1, 2019
@corona10
Copy link
Member Author

corona10 commented Sep 1, 2019

@taleinat @ZackerySpytz cc @pganssle @abalkin

First of all, thanks for the code review.
I 've reflected the review for this PR.

However, other comments have been raised by the core developer on whether this patch is acceptable.
IMHO, It is a good idea to review the patch after the discussion is complete.

Again, thank you for the code reviews. :)

@corona10 corona10 changed the title [WIP] bpo-24416: Return a namedtuple from date.isocalendar() bpo-24416: Return a namedtuple from date.isocalendar() Sep 1, 2019
Doc/library/datetime.rst Outdated Show resolved Hide resolved
@brandtbucher brandtbucher added the type-feature A feature request or enhancement label Sep 1, 2019
@corona10
Copy link
Member Author

corona10 commented Sep 2, 2019

@rhettinger
Is there anything can review with this PR except updating PR naming and updating documentation?

Copy link
Member

@pganssle pganssle left a comment

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.

Lib/test/datetimetester.py Outdated Show resolved Hide resolved
@rhettinger
Copy link
Contributor

rhettinger commented Sep 8, 2019

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 rhettinger closed this Sep 8, 2019
@pganssle
Copy link
Member

pganssle commented Sep 8, 2019

@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).

@pganssle pganssle reopened this Sep 8, 2019
@tim-one tim-one changed the title bpo-24416: Return a namedtuple from date.isocalendar() bpo-24416: Return a structseq from date.isocalendar() Sep 8, 2019
@tim-one
Copy link
Member

tim-one commented Sep 8, 2019

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 sys.float_info).

@rhettinger
Copy link
Contributor

rhettinger commented Sep 8, 2019

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.

@rhettinger rhettinger self-assigned this Sep 8, 2019
@tim-one
Copy link
Member

tim-one commented Sep 8, 2019

Raymond, the actual current code here uses PyStructSequence_XXX calls. Not named tuples anymore. That's why I changed the title 😄.

@rhettinger
Copy link
Contributor

rhettinger commented Sep 8, 2019

I had make a quick scan of the latest version and didn't expect to see from collections import namedtuple on line 11 of Lib/datetime.py.

@tim-one
Copy link
Member

tim-one commented Sep 8, 2019

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.

@rhettinger
Copy link
Contributor

rhettinger commented Sep 8, 2019

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".

>>> import time
>>> time.localtime()
time.struct_time(tm_year=2019, tm_mon=9, tm_mday=8, tm_hour=16, tm_min=50, tm_sec=17, tm_wday=6, tm_yday=251, tm_isdst=1)
>>> type(_)
<class 'time.struct_time'>

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

@corona10
Copy link
Member Author

corona10 commented Dec 17, 2019

I have made the requested changes; please review again

@bedevere-bot
Copy link

bedevere-bot commented Dec 17, 2019

Thanks for making the requested changes!

@pganssle, @taleinat: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from pganssle Dec 17, 2019
@corona10
Copy link
Member Author

corona10 commented Dec 17, 2019

cc @vstinner

@@ -1210,6 +1210,36 @@ def __reduce__(self):
else:
return (self.__class__, args, state)


class IsoCalendarDate(tuple):

Copy link

@pppery pppery Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__slots__ = ()

Copy link
Member Author

@corona10 corona10 Jan 16, 2020

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?

@pganssle
Copy link
Member

pganssle commented May 8, 2020

@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 _IsoCalendar or something (particularly if we can overload the __repr__ to have it return IsoCalendar(...) instead?) if it's too complicated to do anything else.

@corona10
Copy link
Member Author

corona10 commented May 9, 2020

@pganssle

Hmm, I should remember what I tried before for this issue :)

AFAIK(??) I still prefer the current PR implementation.
Since #17651 is too verbose. (It's just my opinion)
he current implementation is able to compatible with pure python code.
This PR can be the same level of verbose but we can bring compatible issues easily.
(You know namedtuple and structseq is quite different.)

But if you decide specific requirements then we can change the implementation.
And I prefer the start with new PR.
We(or You) can create a new PR to start.

@corona10
Copy link
Member Author

corona10 commented May 9, 2020

or we have to think that this issue is should be solved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting change review type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet