Skip to content

Fix timezone type annotations for now helpers - #1016

Open
kokokoXUY wants to merge 1 commit into
python-pendulum:masterfrom
kokokoXUY:fix/now-stdlib-timezone-types
Open

kokokoXUY wants to merge 1 commit into
python-pendulum:masterfrom
kokokoXUY:fix/now-stdlib-timezone-types

Conversation

@kokokoXUY

Copy link
Copy Markdown

Fixes #783.

The top-level now() annotation excludes datetime.timezone and zoneinfo.ZoneInfo, even though DateTime.now() and the runtime already accept datetime.tzinfo. The same mismatch affects today(), tomorrow(), and yesterday().

This aligns the four public annotations with their runtime behavior, adds typed regression coverage for standard-library UTC and ZoneInfo("Europe/Paris"), and updates the README and instantiation guide. No runtime behavior changes.

Validation on Windows CPython 3.12.7:

  • Pure-Python suite (PENDULUM_EXTENSIONS=0): 1847 passed, 5 skipped.
  • Focused mypy on tests/test_main.py: passed. Before the change it reported four incompatible-argument errors for these helpers.
  • Ruff 0.14.11 check and format check: passed.
  • Full mypy: one pre-existing unused-ignore error in src/pendulum/tz/timezone.py:65; reproduced on unchanged master.
  • The native Rust extension was not tested locally because this machine has no Rust toolchain; CI covers that matrix.

AI assistance: Codex helped investigate, implement, and test this change. I reviewed the resulting diff and test results.

The public now, today, tomorrow, and yesterday helpers already accept datetime.tzinfo objects at runtime. Align their signatures with DateTime.now and cover standard library timezone and ZoneInfo inputs with typed tests.

Fixes python-pendulum#783.

This branch has not been deployed

No deployments
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.

pendulum.now() type hint doesn't allow datetime.timezone

1 participant