-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
gh-69142: add %:z strftime format code #95983
gh-69142: add %:z strftime format code #95983
Conversation
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
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.
Very elegant, and the code LGTM. But would you be so kind as to add a few unit tests?
@gvanrossum thanks. i even tried to start with unit tests, but it looked hard to fit in the existing test code. but i'll try again... :-) |
Here are the tests for %Z: https://github.com/python/cpython/blob/main/Lib/test/datetimetester.py#L1453 You could add another method, create the datetime instances that you need, then compare method calls with expected outputs. |
datetime.isoformat generates the tzoffset with colons, but there was no format code to make strftime output the same format. for simplicity and consistency the %:z formatting behaves mostly as %z, with the exception of adding colons. this includes the dynamic behaviour of adding seconds and microseconds only when needed (when not 0). this fixes the still open "generate" part of this issue: python#69142
d45e368
to
7d95910
Compare
@merwok thanks. @gvanrossum first attempt was very elegant / short, but incorrect:
|
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 haven't tried to look into why the tests still fail. You know you can run tests locally right?
Also, please don't force-push (which I think you've done) once the review is under way. We'll squash-merge in the end anyway.
Please avoid force pushes for Python PRs: https://devguide.python.org/getting-started/pull-request-lifecycle/index.html |
Of course I ran the tests locally before pushing (but maybe in an unusual way), so there is this interesting finding (on macOS 12, in case it matters):
|
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.
There seems to be still something failing. Do you need help figuring that out?
(as seen for the other replacements)
@gvanrossum yes, i could not find the cause for the strange behaviour yet. Update: Looks like _Fast tests are ok vs _Pure tests are broken. Ah, just found |
That patchcheck automation is not very helpful. It does not show errors, nor line numbers, just recommends to run
|
it works for me, and I do have the recommended setup with an |
Misc/NEWS.d/next/Library/2022-08-14-18-59-54.gh-issue-69142.6is5Pq.rst
Outdated
Show resolved
Hide resolved
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.
Getting very close. I have some nits to pick about the docs.
@kumaraditya303 Have you reviewed datetime.py and is it to your liking?
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.
Have you reviewed datetime.py and is it to your liking?
LGTM
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.
Yes! I'll merge. Thanks TW for the PR and thanks Kumar for all the review work you did.
BTW, will we have to wait some years for this until 3.12 becomes minimum requirement or can this go into older pythons also? |
Alas, this looks like a new feature to me so it won't be backported. |
OK, pity. OTOH, even if it were backported, it would only go into 3.11.latest, so would not help if somebody has 3.11.lessthanthat. |
|
I don't see how this change could break test_multiprocessing_forkserver. From the logs it appears that the first time this test ran it exceeded the 15 minute time limit. The second time it ran fine. Let's ignore this unless the buildbot police get involved. |
datetime.isoformat generates the tzoffset with colons, but there
was no format code to make strftime output the same format.
for simplicity and consistency the %:z formatting behaves mostly
as %z, with the exception of adding colons. this includes the
dynamic behaviour of adding seconds and microseconds only when
needed (when not 0).
this fixes the still open "generate" part of this issue:
#69142