Skip to content

Make DateTime.astimezone timezone optional - #651

Open
xiehuanyi wants to merge 1 commit into
python-poetry:masterfrom
xiehuanyi:fix/datetime-default-timezone-20261012-r2
Open

xiehuanyi wants to merge 1 commit into
python-poetry:masterfrom
xiehuanyi:fix/datetime-default-timezone-20261012-r2

Conversation

@xiehuanyi

Copy link
Copy Markdown

Summary

Parsed DateTime objects reject value.astimezone() because the wrapper requires tz, while native datetime.astimezone() defaults to the local timezone. Give the wrapper the same optional argument, preserving its existing explicit-timezone behavior and wrapped result type.

Validation: the new regression fails on the unchanged source; all 1185 tests, including the pinned toml-test fixtures, pass after the change. Applicable pre-commit hooks pass. Mypy reports the identical six existing errors on the base and this branch (submodule generator excluded), with no new errors.

Agent Drafting Metadata

  • Agent: OpenAI Codex
  • Model: GPT-6.1 Sol, xhigh
  • Notes: The description and changes in tomlkit/items.py, tests/test_items.py and CHANGELOG.md were prepared with this agent.

Copilot AI balanced review requested due to automatic review settings October 12, 2026 19:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Wkhanex Wkhanex left a comment •

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 checked the changed astimezone method against stdlib behavior for naive, UTC-aware and ZoneInfo-aware datetimes. In all three controls, omitting the argument matched explicit None and the stdlib local-timezone conversion. The existing _new reconstruction path is retained by the patch. A naive input regression would complement the new UTC-aware test, since datetime.astimezone also permits naive inputs. I ran these checks on Python 3.12 using the exact method in a datetime subclass adapter; TOML parsing/trivia reconstruction and the full package tests were not run.

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.

3 participants