Commit e4cbd28
Fix RecursionError when adding to a DateTime with a FixedTimezone (#431)
This seems to have been caused by `bpo-32417`. Before that change,
adding a timedelta to a date/datetime subclass would always return an
instance of date/datetime instead of the subclass. After the change, the
subclass is preserved.
The RecursionError was caused by adding a timedelta to a DateTime. Doing
this uses the `convert` method of the DateTime's timezone to convert the
new DateTime into the correct timezone. In the case of FixedTimezones,
this requires adding the UTC offset of the timezone (a timedelta) to the
DateTime, causing the recursion.
Before bpo-32417, the subclass of the DateTime was dropped while calling
`astimezone`. This meant that the object that was passed into `fromutc`
by `astimezone` was a stdlib datetime, not a Pendulum DateTime. Calling
the stdlib datetime's add function would then do the addition and return
the result (which would then be upconverted back into a Pendulum
DateTime instance). Now, due to the subclass being preserved, the
Pendulum DateTime's add function is being called instead, causing the
recursion.
This commit fixes the RecursionError by always using the stdlib
datetime's addition function to add the offset to the DateTime when
calling fromutc.
bpo-32417: https://bugs.python.org/issue32417
commit: python/cpython@89427cd
Fixes #4221 parent bc32743 commit e4cbd28
2 files changed
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
345 | | - | |
| 345 | + | |
| 346 | + | |
346 | 347 | | |
347 | 348 | | |
348 | 349 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
137 | 138 | | |
138 | | - | |
| 139 | + | |
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
| |||
0 commit comments