Skip to content

Support native timedelta operands in duration arithmetic - #1042

Open
muneikh wants to merge 1 commit into
python-pendulum:masterfrom
muneikh:fix-native-timedelta-arithmetic
Open

muneikh wants to merge 1 commit into
python-pendulum:masterfrom
muneikh:fix-native-timedelta-arithmetic

Conversation

@muneikh

@muneikh muneikh commented Oct 11, 2026

Copy link
Copy Markdown

Dividing a Duration by datetime.timedelta, or using //, % or divmod, raises AttributeError because the native operand has no _to_microseconds() method. Convert native timedelta days, seconds and microseconds with integer arithmetic while retaining the existing Duration path. This also lets a zero native divisor raise the expected ZeroDivisionError.

Fixes #382. Calendar month/year arithmetic described in #799 is outside this fix.

Sixteen new regression cases fail before the fix. The full suite passes (1,886 tests, 3 skips); the duration/interval subset passes (105 tests), and pinned Ruff lint/format checks and focused Mypy pass.

  • Added tests for changed code.
  • Updated documentation for changed code (the existing timedelta arithmetic contract is retained).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error dividing Period by timedelta

1 participant