Commit 1879016
committed
Fix full-day Durations collapsing to zero on PyPy
On PyPy, `Duration.total_seconds()` is overridden to compute the total from
`_days`/`_seconds`/`_microseconds`/etc. But `Duration.__new__` called
`self.total_seconds()` to derive `_total` *before* those attributes were
populated (they are still at their class defaults of 0 at that point), so the
computed total was 0 and the whole duration collapsed to `Duration()`. As a
result `duration(days=1).total_seconds()` returned 0 on PyPy.
Derive the total from `timedelta.total_seconds(self)` instead, which reads the
already-initialized underlying `timedelta` value and is independent of the
PyPy override. Behavior on CPython is unchanged (there the method is not
overridden, so both calls are equivalent).
Closes #8761 parent cbab60c commit 1879016
2 files changed
Lines changed: 21 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
99 | 106 | | |
100 | 107 | | |
101 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
0 commit comments