fix(harness): use UTC as fallback timezone in EnvironmentResolver#28
Open
caoergou wants to merge 1 commit into
Open
fix(harness): use UTC as fallback timezone in EnvironmentResolver#28caoergou wants to merge 1 commit into
caoergou wants to merge 1 commit into
Conversation
When `strptime` with `%z` fails to parse the timezone offset,
the fallback previously produced a naive datetime, violating the
documented contract ("Timezone-aware datetime on the computer").
Now falls back to UTC so `today_date.tzinfo` is always set.
Fixes UnicomAI#26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and Why
EnvironmentContext.today_dateis documented as returning a timezone-aware datetime (docstring: "Timezone-aware datetime on the computer"), and the inline comment inEnvironmentResolver.resolve()reads "Parse into a timezone-aware datetime."However, the
except ValueErrorfallback path produced a naive datetime (notzinfo), suppressing the RuffDTZ007warning with# noqarather than fixing the root cause:The existing test even asserted
env.today_date.tzinfo is None, directly contradicting the documented contract. Any downstream code that performs timezone-aware arithmetic or comparisons ontoday_datewould raise aTypeErroron hosts wheredateoutputs no UTC offset.Fix
Attach UTC explicitly in the fallback path so the
tzinfoguarantee is always upheld:This removes the
# noqa: DTZ007suppression (the warning no longer applies) and aligns the test assertion with the documented contract.Changes
uniharness/harness/environment.py: importUTC; replace naive fallback with.replace(tzinfo=UTC); remove# noqa: DTZ007tests/unit_tests/harness/test_environment.py: update docstring and assertion intest_datetime_without_timezone_fallbackTest Plan
Key test:
tests/unit_tests/harness/test_environment.py::TestResolve::test_datetime_without_timezone_fallback— now assertstzinfo is not None.Fixes #26