fix(examples): replace deprecated datetime.utcnow() in web_search_gpt_oss_helper#669
Open
Ghraven wants to merge 1 commit into
Open
fix(examples): replace deprecated datetime.utcnow() in web_search_gpt_oss_helper#669Ghraven wants to merge 1 commit into
Ghraven wants to merge 1 commit into
Conversation
datetime.utcnow() is deprecated since Python 3.12 and emits a DeprecationWarning when imported in environments configured to surface deprecation warnings. The recommended replacement returns an explicitly timezone-aware UTC datetime instead of a naive one, which also avoids the subtle bug of naive datetimes being compared against aware datetimes elsewhere in user code. Replace 5 occurrences of datetime.utcnow() with datetime.now(timezone.utc) in examples/web_search_gpt_oss_helper.py and add timezone to the datetime import. No behaviour change for the example's downstream use of fetched_at (typed as datetime, accepts both naive and aware values).
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
datetime.utcnow()is deprecated since Python 3.12 and emits aDeprecationWarningwhenever the helper is imported under a strict warnings config. The recommended replacement isdatetime.now(timezone.utc), which also returns a timezone-aware UTC datetime instead of the naive oneutcnow()produces — a small correctness win, since naive UTC datetimes can silently misbehave when compared against aware ones elsewhere in user code.Why
DeprecationWarningfrom the example.fetched_at: datetimeaccepts both naive and aware values.Changes
examples/web_search_gpt_oss_helper.py:timezoneto the existingfrom datetime import datetimeimport.datetime.utcnow()withdatetime.now(timezone.utc).Total: +6/-6 lines, 1 file.
Testing
Pure call-site swap with no logic change. The file parses cleanly (
python -m py_compile). The example still produces the same wall-clock instant forfetched_at, just with atzinfo=UTCattached instead ofNone.