Skip to content

gh-151221: Fix plistlib loading of partial ISO 8601 dates#151217

Open
JavaZeroo wants to merge 3 commits into
python:mainfrom
JavaZeroo:fix/plistlib-partial-date
Open

gh-151221: Fix plistlib loading of partial ISO 8601 dates#151217
JavaZeroo wants to merge 3 commits into
python:mainfrom
JavaZeroo:fix/plistlib-partial-date

Conversation

@JavaZeroo

@JavaZeroo JavaZeroo commented Jun 10, 2026

Copy link
Copy Markdown

Summary:

  • Fix plistlib._date_from_string raising a confusing TypeError when a <date> omits smaller units (e.g. 2024-06Z or 2024Z). The date regex makes month/day/time optional, but the argument list for datetime.datetime() was truncated at the first missing component. Missing components now default to the start of the period.

  • Add coverage for loading partial dates (year only, year-month, etc.).

Tests:

  • ./python -m test test_plistlib

@bedevere-app

bedevere-app Bot commented Jun 10, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@JavaZeroo JavaZeroo changed the title Fix plistlib loading of partial ISO 8601 dates gh-151221: Fix plistlib loading of partial ISO 8601 dates Jun 10, 2026
@JavaZeroo JavaZeroo force-pushed the fix/plistlib-partial-date branch from b6ad3b9 to c2c8258 Compare June 10, 2026 06:43
plistlib's date regex makes the month, day and time components optional,
but _date_from_string stopped building the datetime arguments at the
first missing component, so a partial date such as ``2024-06Z`` raised a
confusing TypeError instead of producing a datetime. Default the omitted
components to the start of the period.
@JavaZeroo JavaZeroo force-pushed the fix/plistlib-partial-date branch from c2c8258 to 526bbb5 Compare June 10, 2026 06:46
@python-cla-bot

python-cla-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@picnixz

picnixz commented Jun 10, 2026

Copy link
Copy Markdown
Member

Please do not force push as required by https://devguide.python.org/getting-started/pull-request-lifecycle/#pullrequest

@picnixz picnixz 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.

Please document this change if there is any public documentation (in Doc/) using a .. versionchanged:: next directive.

@JavaZeroo

Copy link
Copy Markdown
Author

Please document this change if there is any public documentation (in Doc/) using a .. versionchanged:: next directive.

Done — added a versionchanged:: next note in the docs. Sorry about the force-pushes, will avoid them from now on.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33071511 | 📁 Comparing c0c74b2 against main (ff64d8d)

  🔍 Preview build  

2 files changed
± library/plistlib.html
± whatsnew/changelog.html

Comment thread Lib/test/test_plistlib.py
# Smaller units may be omitted; missing components default to the
# start of the period.
for data, expected in [
(b"<plist><date>2024Z</date></plist>",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure if 2024Z is a valid ISO 8601 format. While year only (YYYY) format is ISO, I think timezone designators (in this case Zulu time) can only be attached to complete time value, not a standalone year.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants