From 5622c166862fcd7d3aa47233fc8429dbb721fa61 Mon Sep 17 00:00:00 2001 From: Ghraven <115199279+Ghraven@users.noreply.github.com> Date: Tue, 19 May 2026 03:01:24 +0000 Subject: [PATCH] fix(examples): replace deprecated datetime.utcnow() in web_search helper 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). --- examples/web_search_gpt_oss_helper.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/web_search_gpt_oss_helper.py b/examples/web_search_gpt_oss_helper.py index e3e064c9..bd4b83f1 100644 --- a/examples/web_search_gpt_oss_helper.py +++ b/examples/web_search_gpt_oss_helper.py @@ -2,7 +2,7 @@ import re from dataclasses import dataclass, field -from datetime import datetime +from datetime import datetime, timezone from typing import Any, Dict, List, Optional, Protocol, Tuple from urllib.parse import urlparse @@ -212,7 +212,7 @@ def _build_search_results_page_collection(self, query: str, results: Dict[str, A text='', lines=[], links={}, - fetched_at=datetime.utcnow(), + fetched_at=datetime.now(timezone.utc), ) tb = [] @@ -246,7 +246,7 @@ def _build_search_result_page(self, result: WebSearchResult, link_idx: int) -> P text='', lines=[], links={}, - fetched_at=datetime.utcnow(), + fetched_at=datetime.now(timezone.utc), ) link_fmt = f'【{link_idx}†{result.title}】\n' @@ -275,7 +275,7 @@ def _build_page_from_fetch(self, requested_url: str, fetch_response: Dict[str, A text='', lines=[], links={}, - fetched_at=datetime.utcnow(), + fetched_at=datetime.now(timezone.utc), ) for url, url_results in fetch_response.get('results', {}).items(): @@ -306,7 +306,7 @@ def _build_find_results_page(self, pattern: str, page: Page) -> Page: text='', lines=[], links={}, - fetched_at=datetime.utcnow(), + fetched_at=datetime.now(timezone.utc), ) max_results = 50 @@ -442,7 +442,7 @@ def open( text='', lines=[], links={}, - fetched_at=datetime.utcnow(), + fetched_at=datetime.now(timezone.utc), ) available = sorted(page.links.keys()) available_list = ', '.join(map(str, available)) if available else '(none)'