-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
bpo-28157: Improvements for the time module documentation #928
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
Conversation
|
@csabella, thanks for your PR! By analyzing the history of the files in this pull request, we identified @birkenfeld, @abalkin and @akheron to be potential reviewers. |
Doc/library/time.rst
Outdated
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.
I don't like that the same note is repeated four times. Maybe we can split the functions and constants in two separate sections and place this note in the constants section once.
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.
Thank you. I thought that it wasn't DRY when I was changing it but didn't know about moving things around. I step back and look at the overall layout.
Doc/library/time.rst
Outdated
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.
Please remove "and data items" from the introductory sentence above.
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.
Thank you. I had originally removed it, but then put it back in because I left some of the new data constants (starting with time.CLOCK_HIGHRES.) in that section. I didn't know if I should move the newer data items to the bottom with the deprecated ones or not. Maybe I should change the one on the bottom to be 'Deprecated data items:'?
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.
Please note that the time module also defines a few constants starting with CLOCK_. Their descriptions should also go to the "Constants" section.
CLOCK_MONOTONIC = 6
CLOCK_MONOTONIC_RAW = 4
CLOCK_PROCESS_CPUTIME_ID = 12
CLOCK_REALTIME = 0
CLOCK_THREAD_CPUTIME_ID = 16
|
Thank you for pointing out the math.rst to look at. One question - I'm new to this, so can you send a link instructions on changing pydoc and docstrings? Thanks! |
|
C modules' docstrings are hardcoded in the C files. For the time module, see Modules/timemodule.c. |
|
I've been looking at pydoc math and pydoc time (and the the module.c source). Before I go down the wrong path, I'm not sure I fully understand your comment - "(Also, markup can be improved in the time module docstring. Compare pydoc time and pydoc math.)" The time one is more vebose in the description and it lists the Variables and Functions in the text and then defines them with markup further down. Are you saying the variables and functions should be removed from being written in text within the description? Thanks. |
Yes, I think so. Note that this discussion should probably be held at the b.p.o. issue. |
|
OK, sorry about that. I'll copy my question to there. |
Doc/library/time.rst
Outdated
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.
You may also mention here that these constants are reset when time.tzset() is called. Maybe add "or the last time tzset() is called" after "at module load time".
Doc/library/time.rst
Outdated
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.
Indentation should be the same level as others since the note is talking about altzone, daylight, timezone and tzname constants, not just tzname.
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.
Changed.
Doc/library/time.rst
Outdated
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.
We also need to document which functions of the time modules accept these constants.
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.
I added one comment right under the constants heading. It seemed that all the constants would apply to clock_getres and clock_getttime, so hopefully this is appropriate.
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.
Good point. How about removing clock_settime() from the paragraph below and add a note to CLOCK_REALTIME documentation that says this constant can only be passed to time.clock_settime()?
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.
I've added a note to CLOCK_REALTIME.
Doc/library/time.rst
Outdated
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.
I would suggest adding a link of this section to appropriate members of the time module. For example, see https://docs.python.org/3/library/time.html#time.clock_gettime -- I would add something like
See :ref:`time-clock-id-constants` for a list of accepted values for *clk_id*.to the time.clock_gettime() documentation.
My wording is probably terrible (it's 3 a.m. here and my brain doesn't work well now), but I think you get the idea :)
And don't forget to create a link for the section:
.. _time-clock-id-constants:
Clock ID Constants
------------------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.
@berkerpeksag Thank you for all your suggestions. I added this reference to time.clock_gettime(), time.clock_getres(), and time.clock_settime(). It seems that settime only works for CLOCK_REALTIME though, so maybe it shouldn't link to the whole section? Also, I did not add any references in time.monotonic(), time.perf_counter(), or time.process_time(), but those seem to be shortcuts to time.clock_gettime()?
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.
It seems that settime only works for CLOCK_REALTIME though, so maybe it shouldn't link to the whole section?
Good catch. I'd keep it in the same section, but add something like ":data:`CLOCK_REALTIME` is the only acceptable constant for *clk_id*." to time.clock_settime() documentation. My wording is probably a bit bad, feel free to tweak it :)
Also, I did not add any references in time.monotonic(), time.perf_counter(), or time.process_time(), but those seem to be shortcuts to time.clock_gettime()?
Agreed.
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.
I've added a line to the clock_settime() section.
Doc/library/time.rst
Outdated
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.
We don't need to create a link for this case, but I believe we can still use some markup to make it more readable: ``CLOCK_HIGHRES``
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.
I'm sorry, but I didn't understand this comment.
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.
Yeah, my comment wasn't clear. I meant to say replace CLOCK_HIGHRES with ``CLOCK_HIGHRES``.
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.
@berkerpeksag Thank you for clarifying. I had tried to do that, but, when I did, the tick marks show up in the HTML (after running make html). It doesn't show up here when I cut and paste from the HTML because of Markdown, so I don't know how to show you what it looks like.
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.
That's weird. I don't know why it didn't work. Could you try copy and paste the backticks in line 27 in Doc/library/time.rst? Perhaps something was wrong with my earlier comment.
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.
I was trying to change it next to data::. :-( After looking at it again, I realized what you meant. Sorry about that.
Doc/library/time.rst
Outdated
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.
Maybe "See note below." would be more descriptive?
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.
Changed.
|
This LGTM. @berkerpeksag - it looks like your comments have been addressed. Can this be merged? |
berkerpeksag
left a comment
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.
This looks pretty great, thank you! I just left two minor comments.
Doc/library/time.rst
Outdated
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.
I'd listCLOCK_REALTIME after CLOCK_THREAD_CPUTIME_ID and make it look like in the following format:
Clock ID Constants
------------------
These constants are used as parameters for :func:`clock_getres` and
:func:`clock_gettime`.
.. All CLOCK_* constants except CLOCK_REALTIME documented here.
The following constant is the only parameter that can be sent to
:func:`clock_settime`.
.. data:: CLOCK_REALTIME
System-wide real-time clock. Setting this clock requires
appropriate privileges.
Availability: Unix.
.. versionadded:: 3.3There 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.
Done. Thanks for the suggestion.
Doc/library/time.rst
Outdated
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.
Nit: We use "time zone" and "timezone" a bit inconsistently in this note. I don't know which one is correct, but I don't see a reason to use the both forms here.
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.
Good catch. I hadn't even realized I had done that and googling it seems that both ways is correct, so, as you said, it's best to be consistent. I left the 'T' capitalized, but I wasn't sure if I should 1. make it a link, 2. uppercase the 'C' in constant, or 3. lowercase the 'T'.
|
@berkerpeksag @abalkin Thanks for the review. I've made the additional changes. |
|
Looks great to me, thank you again. I'll let @abalkin do the merging since he's our datetime/time expert (I can do it this weekend in case he's busy with other issues) |
|
Thanks @csabella for the PR, and @berkerpeksag for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6. |
|
GH-3953 is a backport of this pull request to the 3.6 branch. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

https://bugs.python.org/issue28157