-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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-118948: add support for ISO 8601 basic format to datetime
#120553
base: main
Are you sure you want to change the base?
Conversation
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 needs some polishing and simplification in my opinion, especially tests, but looks very good in general :-)
@@ -2176,76 +2177,117 @@ def test_roundtrip(self): | |||
def test_isoformat(self): | |||
t = self.theclass(1, 2, 3, 4, 5, 1, 123) | |||
self.assertEqual(t.isoformat(), "0001-02-03T04:05:01.000123") | |||
self.assertEqual(t.isoformat(basic=True), "00010203T040501.000123") |
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 feel like there has to be a better way to do this (It could also automatically convert it to basic so we don't have to enter both by hand), a helper function would cut down the amount of lines. (Well, it wouldn't increase.)
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 would be out of scope for the PR and in this case, explicit is likely better than implicit IMO.
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.
Out of scope is subjective, you pretty much doubled the amount of tests. I guess it could be a follow up pr. (I don't mind doing it)
def assertIsoFormats(self, t, expected):
self.assertEqual(t.isoformat(), expected)
expected_basic = expected_standard.replace("-", "").replace(":", "")
self.assertEqual(t.isoformat(basic=True), expected_basic)
Four lines to save 40ish.
explicit is likely better than implicit IMO.
Any specific reason, for readability?
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.
Any specific reason, for readability?
Yes, and for tracking bugs in this case. However, if we want to assert the ISO format differently, we should do it in a refactoring PR and not in this one. The ISO format is not the only whose checks could be refactored in some sense IMO.
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@@ -2176,76 +2177,117 @@ def test_roundtrip(self): | |||
def test_isoformat(self): | |||
t = self.theclass(1, 2, 3, 4, 5, 1, 123) | |||
self.assertEqual(t.isoformat(), "0001-02-03T04:05:01.000123") | |||
self.assertEqual(t.isoformat(basic=True), "00010203T040501.000123") |
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 would be out of scope for the PR and in this case, explicit is likely better than implicit IMO.
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
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 guess we can leave refactoring for later. LGTM :-)
In addition to
date
anddatetime
,datetime.time
also supports ISO 8601 basic format (the rationale is to make it consistent).📚 Documentation preview 📚: https://cpython-previews--120553.org.readthedocs.build/