Problem
EnvironmentContext.today_date is documented as returning a timezone-aware datetime:
- The
EnvironmentContext type's docstring states: "Timezone-aware datetime on the computer"
- The comment in
EnvironmentResolver.resolve() reads: "Parse into a timezone-aware datetime."
However, the fallback path in environment.py (line 81) silently produces a naive datetime when strptime with %z fails:
# environment.py line 80-81
except ValueError:
now = datetime.strptime(raw_dt[:19], "%Y-%m-%dT%H:%M:%S") # noqa: DTZ007
The # noqa: DTZ007 suppression is itself a signal that the linter flagged this as a timezone-unaware datetime. The existing test even asserts the broken contract explicitly:
# test_environment.py line 84
assert env.today_date.tzinfo is None # contradicts the documented "timezone-aware" guarantee
Impact
Any downstream code that treats today_date.tzinfo as reliably set — such as timezone-aware arithmetic or comparisons — will raise a TypeError on hosts where the shell's date output lacks a numeric UTC offset (some containers, minimal environments, or locale edge cases).
Proposed Fix
In the except ValueError fallback, attach UTC explicitly so the contract is always satisfied:
from datetime import UTC, datetime
# ...
except ValueError:
now = datetime.strptime(raw_dt[:19], "%Y-%m-%dT%H:%M:%S").replace(tzinfo=UTC)
This removes the need for # noqa: DTZ007 and brings the test assertion in line with the documented contract:
assert env.today_date.tzinfo is not None
The change is minimal (1 import, 1 line, 1 test assertion) and does not affect the happy path.
Problem
EnvironmentContext.today_dateis documented as returning a timezone-aware datetime:EnvironmentContexttype's docstring states: "Timezone-aware datetime on the computer"EnvironmentResolver.resolve()reads: "Parse into a timezone-aware datetime."However, the fallback path in
environment.py(line 81) silently produces a naive datetime whenstrptimewith%zfails:The
# noqa: DTZ007suppression is itself a signal that the linter flagged this as a timezone-unaware datetime. The existing test even asserts the broken contract explicitly:Impact
Any downstream code that treats
today_date.tzinfoas reliably set — such as timezone-aware arithmetic or comparisons — will raise aTypeErroron hosts where the shell'sdateoutput lacks a numeric UTC offset (some containers, minimal environments, or locale edge cases).Proposed Fix
In the
except ValueErrorfallback, attach UTC explicitly so the contract is always satisfied:This removes the need for
# noqa: DTZ007and brings the test assertion in line with the documented contract:The change is minimal (1 import, 1 line, 1 test assertion) and does not affect the happy path.