Skip to content

Commit 661d1ca

Browse files
committed
gh-99772: Address review comments
1 parent fe57d29 commit 661d1ca

3 files changed

Lines changed: 11 additions & 30 deletions

File tree

Lib/_pydatetime.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,10 +1560,10 @@ def _cmp(self, other, allow_mixed=False):
15601560
return 2 # arbitrary non-zero value
15611561
else:
15621562
raise TypeError("cannot compare naive and aware times")
1563-
myus = (((self._hour * 60 + self._minute) * 60 + self._second)
1564-
* 1000000 + self._microsecond - myoff._to_microseconds())
1565-
otus = (((other._hour * 60 + other._minute) * 60 + other._second)
1566-
* 1000000 + other._microsecond - otoff._to_microseconds())
1563+
myus = (((self._hour * 60 + self._minute) * 60 + self._second) * 1000000
1564+
+ self._microsecond - myoff._to_microseconds())
1565+
otus = (((other._hour * 60 + other._minute) * 60 + other._second) * 1000000
1566+
+ other._microsecond - otoff._to_microseconds())
15671567
return _cmp(myus, otus)
15681568

15691569
def __hash__(self):

Lib/test/datetimetester.py

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4678,44 +4678,25 @@ def tzname(self, dt): return self.tz
46784678

46794679
def test_subminute_offset_equality(self):
46804680
t1 = self.theclass(12, tzinfo=timezone.utc)
4681-
t2 = self.theclass(
4682-
12, 0, 1, tzinfo=timezone(timedelta(seconds=1))
4683-
)
4681+
t2 = self.theclass(12, 0, 1, tzinfo=timezone(timedelta(seconds=1)))
46844682
self.assertEqual(t1, t2)
4685-
t2 = self.theclass(
4686-
12, 0, 0, 1,
4687-
tzinfo=timezone(timedelta(microseconds=1)),
4688-
)
4683+
t2 = self.theclass(12, 0, 0, 1, tzinfo=timezone(timedelta(microseconds=1)))
46894684
self.assertEqual(t1, t2)
4690-
t2 = self.theclass(
4691-
11, 59, 59, 999999,
4692-
tzinfo=timezone(timedelta(microseconds=-1)),
4693-
)
4685+
t2 = self.theclass(11, 59, 59, 999999, tzinfo=timezone(timedelta(microseconds=-1)))
46944686
self.assertEqual(t1, t2)
46954687

46964688
def test_subminute_offset_ordering(self):
46974689
t1 = self.theclass(0, tzinfo=timezone.utc)
4698-
t2 = self.theclass(
4699-
0, tzinfo=timezone(timedelta(microseconds=1))
4700-
)
4701-
self.assertNotEqual(t1, t2)
4690+
t2 = self.theclass(0, tzinfo=timezone(timedelta(microseconds=1)))
47024691
self.assertGreater(t1, t2)
47034692

47044693
def test_subminute_offset_hash(self):
47054694
t1 = self.theclass(12, tzinfo=timezone.utc)
4706-
t2 = self.theclass(
4707-
12, 0, 1, tzinfo=timezone(timedelta(seconds=1))
4708-
)
4695+
t2 = self.theclass(12, 0, 1, tzinfo=timezone(timedelta(seconds=1)))
47094696
self.assertEqual(hash(t1), hash(t2))
4710-
t2 = self.theclass(
4711-
12, 0, 0, 1,
4712-
tzinfo=timezone(timedelta(microseconds=1)),
4713-
)
4697+
t2 = self.theclass(12, 0, 0, 1, tzinfo=timezone(timedelta(microseconds=1)))
47144698
self.assertEqual(hash(t1), hash(t2))
4715-
t2 = self.theclass(
4716-
11, 59, 59, 999999,
4717-
tzinfo=timezone(timedelta(microseconds=-1)),
4718-
)
4699+
t2 = self.theclass(11, 59, 59, 999999, tzinfo=timezone(timedelta(microseconds=-1)))
47194700
self.assertEqual(hash(t1), hash(t2))
47204701

47214702
def test_hash_edge_cases(self):

Misc/NEWS.d/next/Library/2026-08-01-20-21-37.gh-issue-155023.q7M3vP.rst renamed to Misc/NEWS.d/next/Library/2026-08-01-20-21-37.gh-issue-99772.q7M3vP.rst

File renamed without changes.

0 commit comments

Comments
 (0)