Conversation
| return isinstance(other, Timezone) and self.key == other.key | ||
|
|
||
| def __hash__(self) -> int: | ||
| return hash(self.key) |
There was a problem hiding this comment.
This is slightly incorrect, as it means that "UTC" and Timezone("UTC") would hash to the same value
There was a problem hiding this comment.
Thanks for pointing this out. Updated in b623446 to hash (Timezone, self.key), giving named timezones a type-qualified hash input. Using the base Timezone class also preserves equal hashes for subclasses that inherit the existing equality behavior.
Added regression coverage for equal base/subclass instances as dictionary keys and set members across UTC, Europe/Paris, and America/New_York.
Local validation on Windows / CPython 3.13 in pure-Python mode: 641 timezone tests passed, 5 skipped. The full suite has 1,843 passed, 5 skipped, and the same two failures reproduced on the original upstream checkout (test_diff_for_humans_now_and_future_month and test_parse). Mypy 1.13.0 passes across 223 files. The Rust extension was not validated.
Ruff 0.14.11 lint and format checks pass as well. This patch and validation were prepared with Codex assistance.
Fixes #1008.
Adding
Timezone.__eq__in 3.1.0 made named timezone objects unhashable. This breaks calls such ashash(pendulum.Timezone("UTC"))and using a timezone as a dictionary key or set element.Implement
__hash__using the timezone key, matching the existing equality rule. The regression tests construct equal objects withTimezone.no_cache()and verify equal hashes, dictionary lookup, and set deduplication. A separate test checks dictionary lookup for two distinct timezone names.Validation
Tested locally on Windows with Python 3.13.13:
PENDULUM_EXTENSIONS=0): 1,840 passed, 5 skipped, 2 failed. A clean checkout of the original commit produces the same two failures, with 1,836 passing tests. The failing tests aretests/date/test_diff.py::test_diff_for_humans_now_and_future_monthandtests/test_parsing.py::test_parse.git diff --checkpasses.The native extension build could not run on this machine because the MSVC
link.exelinker is unavailable. The Python source tests use the same pure-Python mode exercised by the repository's CI.Pull Request Check List
This patch, regression tests, and PR description were prepared with OpenAI Codex assistance. The reported reproductions and tests were executed locally.