Skip to content

Recognize naive datetimes with an offsetless tzinfo - #474

Open
KennyMcSimpson wants to merge 1 commit into
python-humanize:mainfrom
KennyMcSimpson:fix/naive-datetime-awareness
Open

KennyMcSimpson wants to merge 1 commit into
python-humanize:mainfrom
KennyMcSimpson:fix/naive-datetime-awareness

Conversation

@KennyMcSimpson

Copy link
Copy Markdown

Python defines a datetime as naive when its tzinfo.utcoffset(value) returns None, even if tzinfo itself is set (official definition). Humanize currently checks only tzinfo is not None: naturalday() and naturaldate() fall back to the raw datetime string, while naturaltime() raises TypeError: can't subtract offset-naive and offset-aware datetimes for this valid naive input.

Use utcoffset() is not None in the three awareness checks. Add regressions comparing these datetimes with the same wall-clock value after removing tzinfo, controls for ordinary naive and genuinely aware UTC datetimes, and coverage for naturaltime()'s value and when arguments independently and together. No exception handling is broadened.

Validation on Windows / Python 3.13:

  • New cases against unchanged source: 6 failed, 8 passed. Corrected time-module tests: 406 passed.
  • Full tox tests and source doctests: 905 passed, 2 skipped. All 36 locale catalogs were compiled; the two skips require system gettext translation-update tools. Benchmark timing was disabled.
  • Pinned mypy 2.3.1: no issues in 14 files. Pinned Ruff/Black and all hooks applicable to the changed files passed.
  • Full-repository prek passed every applicable hook except validate-pyproject: its installed package is missing pyproject_toml.schema.json and crashes before validating the unchanged project configuration.

Developed with OpenAI Codex assistance.

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.

1 participant