Title: Fix full-day Durations collapsing to zero on PyPy (#876) by uttam12331 · Pull Request #980 · python-pendulum/pendulum · GitHub
Open Graph Title: Fix full-day Durations collapsing to zero on PyPy (#876) by uttam12331 · Pull Request #980 · python-pendulum/pendulum
X Title: Fix full-day Durations collapsing to zero on PyPy (#876) by uttam12331 · Pull Request #980 · python-pendulum/pendulum
Description: Summary Closes #876. On PyPy, duration(days=1) (and any whole-day / full-value duration) returned an empty Duration() with total_seconds() == 0. Root cause On PyPy, Duration defines its own total_seconds() (the if PYPY: branch) that computes the total from self._years, self._months, self._weeks/self._remaining_days/self._days, self._seconds and self._microseconds. But Duration.__new__ used self.total_seconds() to derive self._total: total = self.total_seconds() - (years * 365 + months * 30) * SECONDS_PER_DAY at a point before those _days/_seconds/… attributes are assigned (a few lines later). During construction they are still at their class defaults of 0, so on PyPy total_seconds() returns 0, _total becomes 0, and the subsequent normalization zeroes out the whole duration. On CPython the method isn't overridden, so timedelta.total_seconds() runs and the value is correct — which is why the bug is PyPy-only. Fix Derive the total from timedelta.total_seconds(self), which reads the already-initialized underlying timedelta value and is independent of the PyPy override. On CPython this is equivalent to the previous call, so behavior there is unchanged. Tests Added test_new_does_not_depend_on_total_seconds_override, which runs on CPython: it monkeypatches Duration.total_seconds to return 0.0 (mimicking the PyPy override reading not-yet-set attributes) and asserts duration(days=1)._total == 86400.0. It fails on master (_total == 0.0) and passes with this change. Full tests/duration/ suite passes (48 passed); ruff check/ruff format clean.
Open Graph Description: Summary Closes #876. On PyPy, duration(days=1) (and any whole-day / full-value duration) returned an empty Duration() with total_seconds() == 0. Root cause On PyPy, Duration defines its own total_s...
X Description: Summary Closes #876. On PyPy, duration(days=1) (and any whole-day / full-value duration) returned an empty Duration() with total_seconds() == 0. Root cause On PyPy, Duration defines its own total_s...
Opengraph URL: https://github.com/python-pendulum/pendulum/pull/980
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a01d01da-832c-5eb7-6ab7-79237fa6e489 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8804:1B09F6:445BDE:5E2E91:6B046F89 |
| html-safe-nonce | 82114ff738e055b243da1cfd8824440d6a650859815906f4ff5df7ef41bb26c2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODA0OjFCMDlGNjo0NDVCREU6NUUyRTkxOjZCMDQ2Rjg5IiwidmlzaXRvcl9pZCI6IjE2MDExMDg1OTI2MjM5MDE1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 77c2284d926d65fde18e35fbb28757d792a7ca27e6aa2837229433a94dfe8da1 |
| hovercard-subject-tag | pull_request:3993503992 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-pendulum/pendulum/pull/980/files |
| twitter:image | https://avatars.githubusercontent.com/u/159913047?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/159913047?s=400&v=4 |
| og:image:alt | Summary Closes #876. On PyPy, duration(days=1) (and any whole-day / full-value duration) returned an empty Duration() with total_seconds() == 0. Root cause On PyPy, Duration defines its own total_s... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python-pendulum/pendulum git https://github.com/python-pendulum/pendulum.git |
| octolytics-dimension-user_id | 191041900 |
| octolytics-dimension-user_login | python-pendulum |
| octolytics-dimension-repository_id | 62095504 |
| octolytics-dimension-repository_nwo | python-pendulum/pendulum |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 62095504 |
| octolytics-dimension-repository_network_root_nwo | python-pendulum/pendulum |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width