René's URL Explorer Experiment


Title: Preserve the fold when pickling DateTime by Duo-ee · Pull Request #1073 · python-pendulum/pendulum · GitHub

Open Graph Title: Preserve the fold when pickling DateTime by Duo-ee · Pull Request #1073 · python-pendulum/pendulum

X Title: Preserve the fold when pickling DateTime by Duo-ee · Pull Request #1073 · python-pendulum/pendulum

Description: Pull Request Check List Added tests for changed code. Updated documentation for changed code — pickling is not described in docs/, nothing to update. Fixes #908. What was wrong DateTime.__reduce_ex__() handed the class plus the 8-tuple from _getstate() to pickle, so the fold flag was never serialized. Unpickling a DateTime that sits on the second occurrence of an ambiguous wall time gave back the first occurrence instead: different offset, timestamp off by an hour. import pickle import pendulum chicago = pendulum.timezone("America/Chicago") after = pendulum.datetime(2024, 11, 3, 7, tz="utc").astimezone(chicago) after.timestamp() # 1730617200.0, 01:00 -06:00, fold=1 pickle.loads(pickle.dumps(after)).timestamp() # master: 1730613600.0 (01:00 -05:00, fold=0); this branch: 1730617200.0 Why not restore through create() #909 (self.create plus a 9th element in _getstate()) does fix the timestamp above, but routing the state through create() re-normalizes the instance. Measured on master with that approach: a zoneinfo.ZoneInfo tzinfo comes back as FixedTimezone/Timezone, and a wall time that does not exist (2024-03-10 02:30 in Chicago, which can only be built with the constructor) moves to 01:30 and changes its timestamp. This branch restores from the raw state instead: a module-level _restore_datetime() builds cls(*state, fold=fold) with no timezone conversion and the original tzinfo. fold has to be passed as a keyword because it is keyword-only for datetime.__new__() — which is also why the class itself cannot stay the callable. copy.copy() goes through the same __reduce_ex__() and is fixed by this too (copy.deepcopy() was already correct). Compatibility Pickles written by older versions still load: they store the class plus the 8-tuple, which still builds a valid instance, they only lack the fold they never contained. Checked by dumping with master and loading with this branch for 6 cases × 6 protocols (36 files): 36/36 load with identical type/value/timestamp, except the ambiguous fold=1 case where an old stream has nothing to restore from. Tests Added to tests/datetime/test_behavior.py: fold 0 and 1 across protocols 0-5, shallow copy, and tzinfo preservation. On master 8 of the 14 new cases fail (six fold=1 pickle cases, shallow copy, and the tzinfo case through its offset/timestamp assertions); all pass here. Local run, Python 3.12.14 with the versions pinned in poetry.lock / prek.toml (python-dateutil 2.9.0.post0, pytest 9.0.3, ruff 0.14.11): PENDULUM_EXTENSIONS=0 python -m pytest -q tests → 1882 passed, 5 skipped (master: 1868 passed, 5 skipped) python -m mypy → no issues in 228 files ruff check / ruff format --check → clean Not covered locally: the maturin develop extension build and the free-threaded 3.14t / 3.15t jobs. The change is pure Python and does not touch parsing. Side note, not changed here pendulum.Time._getstate() has the same shape and also loses fold when pickled (Time(1, 30, tzinfo=timezone, fold=1) comes back with fold=0). Happy to extend this PR or send a separate one if you want it fixed too. AI assistance disclosure: developed with AI assistance, as disclosed in #1039. Every number above was produced by running the commands listed.

Open Graph Description: Pull Request Check List Added tests for changed code. Updated documentation for changed code — pickling is not described in docs/, nothing to update. Fixes #908. What was wrong DateTime.__reduc...

X Description: Pull Request Check List Added tests for changed code. Updated documentation for changed code — pickling is not described in docs/, nothing to update. Fixes #908. What was wrong DateTime.__reduc...

Opengraph URL: https://github.com/python-pendulum/pendulum/pull/1073

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.3

react-profiling0
react-import-mapreact,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-controllerpull_requests
route-actionfiles
fetch-noncev2:faa00c8a-2d85-9dd9-1937-07cd405e362c
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idDEFA:208411:1EB3CF:2A2AA3:6B0466E5
html-safe-noncea961752e51bdadaf80ebeeb163f6209b540a05fefee234cdc859f8c26a13a417
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERUZBOjIwODQxMToxRUIzQ0Y6MkEyQUEzOjZCMDQ2NkU1IiwidmlzaXRvcl9pZCI6IjEwMzgzODQwMTAwNDIzMDQyMzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacc8f0758db99da4949a912d0ef2d840dc730bf59a3bb2fe2104915ab2ac56ca93
hovercard-subject-tagpull_request:5051038513
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python-pendulum/pendulum/pull/1073/files
twitter:imagehttps://avatars.githubusercontent.com/u/113885053?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/113885053?s=400&v=4
og:image:altPull Request Check List Added tests for changed code. Updated documentation for changed code — pickling is not described in docs/, nothing to update. Fixes #908. What was wrong DateTime.__reduc...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python-pendulum/pendulum git https://github.com/python-pendulum/pendulum.git
octolytics-dimension-user_id191041900
octolytics-dimension-user_loginpython-pendulum
octolytics-dimension-repository_id62095504
octolytics-dimension-repository_nwopython-pendulum/pendulum
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id62095504
octolytics-dimension-repository_network_root_nwopython-pendulum/pendulum
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseca4d07a7cef4e4b75f821dc25e7300d80c1450a9
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python-pendulum/pendulum/pull/1073/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-pendulum%2Fpendulum%2Fpull%2F1073%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-pendulum%2Fpendulum%2Fpull%2F1073%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python-pendulum%2Fpendulum
Reloadhttps://github.com/python-pendulum/pendulum/pull/1073/files
Reloadhttps://github.com/python-pendulum/pendulum/pull/1073/files
Reloadhttps://github.com/python-pendulum/pendulum/pull/1073/files
python-pendulumhttps://github.com/python-pendulum
pendulumhttps://github.com/python-pendulum/pendulum
Codehttps://github.com/python-pendulum/pendulum
Issues211 (211)https://github.com/python-pendulum/pendulum/issues
Pull requests96 (96)https://github.com/python-pendulum/pendulum/pulls
Discussionshttps://github.com/python-pendulum/pendulum/discussions
Actionshttps://github.com/python-pendulum/pendulum/actions
Projectshttps://github.com/python-pendulum/pendulum/projects
Security and qualityhttps://github.com/python-pendulum/pendulum/security
Insightshttps://github.com/python-pendulum/pendulum/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython-pendulum%2Fpendulum%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython-pendulum%2Fpendulum%2Fissues%2Fnew%2Fchoose
Duo-eehttps://github.com/Duo-ee
python-pendulum:masterhttps://github.com/python-pendulum/pendulum/tree/master
Duo-ee:fix/datetime-pickle-preserves-foldhttps://github.com/Duo-ee/pendulum/tree/fix/datetime-pickle-preserves-fold
Conversation 2 https://github.com/python-pendulum/pendulum/pull/1073
Commits 1 https://github.com/python-pendulum/pendulum/pull/1073/commits
Checks 0 https://github.com/python-pendulum/pendulum/pull/1073/checks
Files changed https://github.com/python-pendulum/pendulum/pull/1073/files
Please reload this pagehttps://github.com/python-pendulum/pendulum/pull/1073/files
Preserve the fold when pickling DateTime https://github.com/python-pendulum/pendulum/pull/1073/files#top
Show all changes 1 commit https://github.com/python-pendulum/pendulum/pull/1073/files
f97c213 Preserve the fold when pickling DateTime Oct 28, 2026 https://github.com/python-pendulum/pendulum/pull/1073/commits/f97c2137dc7fa8663138f72f56ad1466dfeec136
Clear filters https://github.com/python-pendulum/pendulum/pull/1073/files
Please reload this pagehttps://github.com/python-pendulum/pendulum/pull/1073/files
Please reload this pagehttps://github.com/python-pendulum/pendulum/pull/1073/files
datetime.py https://github.com/python-pendulum/pendulum/pull/1073/files#diff-fd3075037174c266854a47f3e198f150b4d07ecdb161487d952a5b67b9b4da4a
test_behavior.py https://github.com/python-pendulum/pendulum/pull/1073/files#diff-b2b528e2fbda790445206b74f594be601a5165c4bdd5b1f947cd583d7049d866
src/pendulum/datetime.pyhttps://github.com/python-pendulum/pendulum/pull/1073/files#diff-fd3075037174c266854a47f3e198f150b4d07ecdb161487d952a5b67b9b4da4a
View file https://github.com/python-pendulum/pendulum/blob/f97c2137dc7fa8663138f72f56ad1466dfeec136/src/pendulum/datetime.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-pendulum/pendulum/pull/1073/{{ revealButtonHref }}
https://github.com/python-pendulum/pendulum/pull/1073/files#diff-fd3075037174c266854a47f3e198f150b4d07ecdb161487d952a5b67b9b4da4a
https://github.com/python-pendulum/pendulum/pull/1073/files#diff-fd3075037174c266854a47f3e198f150b4d07ecdb161487d952a5b67b9b4da4a
https://github.com/python-pendulum/pendulum/pull/1073/files#diff-fd3075037174c266854a47f3e198f150b4d07ecdb161487d952a5b67b9b4da4a
https://github.com/python-pendulum/pendulum/pull/1073/files#diff-fd3075037174c266854a47f3e198f150b4d07ecdb161487d952a5b67b9b4da4a
tests/datetime/test_behavior.pyhttps://github.com/python-pendulum/pendulum/pull/1073/files#diff-b2b528e2fbda790445206b74f594be601a5165c4bdd5b1f947cd583d7049d866
View file https://github.com/python-pendulum/pendulum/blob/f97c2137dc7fa8663138f72f56ad1466dfeec136/tests/datetime/test_behavior.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-pendulum/pendulum/pull/1073/{{ revealButtonHref }}
https://github.com/python-pendulum/pendulum/pull/1073/files#diff-b2b528e2fbda790445206b74f594be601a5165c4bdd5b1f947cd583d7049d866
https://github.com/python-pendulum/pendulum/pull/1073/files#diff-b2b528e2fbda790445206b74f594be601a5165c4bdd5b1f947cd583d7049d866
https://github.com/python-pendulum/pendulum/pull/1073/files#diff-b2b528e2fbda790445206b74f594be601a5165c4bdd5b1f947cd583d7049d866
https://github.com/python-pendulum/pendulum/pull/1073/files#diff-b2b528e2fbda790445206b74f594be601a5165c4bdd5b1f947cd583d7049d866
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.