From 26f428da216f0468cacfe594d2294f824bd5e39b Mon Sep 17 00:00:00 2001 From: Stepan Shamaiev <59963936+skippdot@users.noreply.github.com> Date: Tue, 1 Sep 2026 22:40:19 +0300 Subject: [PATCH] fix: import urllib.parse explicitly instead of relying on side effects - Replace `import urllib` with `import urllib.parse` in _helpers.py, discovery.py, http.py and model.py, which all call `urllib.parse.*` - `import urllib` does not import submodules; the attribute only exists once some other module has imported urllib.parse, so _helpers crashed with AttributeError when used before any such import, and the other three modules depended on httplib2 importing it transitively - Call sites are unchanged; this also fixes the 7 AttributeError failures when running tests/test__helpers.py in isolation Fixes #2803 --- googleapiclient/_helpers.py | 2 +- googleapiclient/discovery.py | 2 +- googleapiclient/http.py | 2 +- googleapiclient/model.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/googleapiclient/_helpers.py b/googleapiclient/_helpers.py index 17b8a171514..c63d08448e4 100644 --- a/googleapiclient/_helpers.py +++ b/googleapiclient/_helpers.py @@ -17,7 +17,7 @@ import functools import inspect import logging -import urllib +import urllib.parse logger = logging.getLogger(__name__) diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py index 16e02bb4ac9..4e92b2cc1bd 100644 --- a/googleapiclient/discovery.py +++ b/googleapiclient/discovery.py @@ -37,7 +37,7 @@ import mimetypes import os import re -import urllib +import urllib.parse import google.api_core.client_options from google.auth.exceptions import MutualTLSChannelError diff --git a/googleapiclient/http.py b/googleapiclient/http.py index d5d2b737e60..5aad0768548 100644 --- a/googleapiclient/http.py +++ b/googleapiclient/http.py @@ -32,7 +32,7 @@ import random import socket import time -import urllib +import urllib.parse import uuid import httplib2 diff --git a/googleapiclient/model.py b/googleapiclient/model.py index dee1cb7f377..52363e79b20 100644 --- a/googleapiclient/model.py +++ b/googleapiclient/model.py @@ -26,7 +26,7 @@ import json import logging import platform -import urllib +import urllib.parse import warnings from googleapiclient import version as googleapiclient_version