Skip to content

gh-86165: Fix Time2Internaldate with datetime timetuple#151844

Merged
serhiy-storchaka merged 6 commits into
python:mainfrom
yuanx749:imaplib
Jul 2, 2026
Merged

gh-86165: Fix Time2Internaldate with datetime timetuple#151844
serhiy-storchaka merged 6 commits into
python:mainfrom
yuanx749:imaplib

Conversation

@yuanx749

Copy link
Copy Markdown
Contributor

Fixes gh-86165.

The issue explains the cause clearly: datetime.datetime.timetuple() returns a time.struct_time with tm_gmtoff present but set to None, so the AttributeError fallback is skipped.

This change falls back to the local timezone offset when tm_gmtoff is None.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

Comment thread Lib/imaplib.py Outdated
Comment on lines +1847 to +1850
try:
gmtoff = date_time.tm_gmtoff
except AttributeError:
gmtoff = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be written as

gmtoff = getattr(date_time, 'tm_gmtoff', None)

But it is up to you.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this is more compact. Updated, thanks for the review.

@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 2, 2026
@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) July 2, 2026 14:34
@serhiy-storchaka serhiy-storchaka merged commit 460fe13 into python:main Jul 2, 2026
93 of 95 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @yuanx749 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jul 2, 2026

Copy link
Copy Markdown

GH-152895 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 2, 2026
@bedevere-app

bedevere-app Bot commented Jul 2, 2026

Copy link
Copy Markdown

GH-152896 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 2, 2026
@bedevere-app

bedevere-app Bot commented Jul 2, 2026

Copy link
Copy Markdown

GH-152897 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 2, 2026
@yuanx749 yuanx749 deleted the imaplib branch July 2, 2026 15:20
serhiy-storchaka pushed a commit that referenced this pull request Jul 2, 2026
…1844) (GH-152897)

(cherry picked from commit 460fe13)

Co-authored-by: Xiao Yuan <yuanx749@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request Jul 2, 2026
…1844) (GH-152896)

(cherry picked from commit 460fe13)

Co-authored-by: Xiao Yuan <yuanx749@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request Jul 2, 2026
…1844) (GH-152895)

(cherry picked from commit 460fe13)

Co-authored-by: Xiao Yuan <yuanx749@gmail.com>
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.

imaplib Time2Internaldate crashing with time.struct_time supplied from datetime.timetuple()

2 participants