From ad8e57793d8cf480d8ebba4905aca26baa0e2e53 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Sun, 7 Jun 2026 22:08:01 -0700 Subject: [PATCH] fix(hermes_time): implement reset_cache() referenced in docstrings (#41728) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The module docstring and get_timezone()/cache comments documented a reset_cache() helper for forcing tz re-resolution after config changes, but the function was never defined — doc-followers calling it hit AttributeError. Adds the helper to clear the cached tz state. Surfaced in #32043. --- hermes_time.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hermes_time.py b/hermes_time.py index aceb82b3e5b..afff8355fe7 100644 --- a/hermes_time.py +++ b/hermes_time.py @@ -88,6 +88,19 @@ def get_timezone() -> Optional[ZoneInfo]: return _cached_tz +def reset_cache() -> None: + """Clear the cached timezone so the next call re-resolves it. + + Call this after the configured timezone may have changed (e.g. after a + config edit or ``HERMES_TIMEZONE`` update) to force ``get_timezone()`` / + ``now()`` to read the new value instead of the value cached at first use. + """ + global _cached_tz, _cached_tz_name, _cache_resolved + _cached_tz = None + _cached_tz_name = None + _cache_resolved = False + + def now() -> datetime: """ Return the current time as a timezone-aware datetime.