From a4d83cb35617c743e75450bca7ddbbaa8989ab97 Mon Sep 17 00:00:00 2001 From: Hongming Wang Date: Thu, 30 Apr 2026 22:45:04 -0700 Subject: [PATCH] chore(adapter): drop redundant urlparse imports + dead ternary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Self-review follow-up to #19. Two cosmetic cleanups: - urlparse is now imported at module-top (added in #17 alongside the auth-mode classification) so the two inline `from urllib.parse import urlparse` statements inside conditional branches are redundant. - The log-format ternary " (custom upstream)" if base_url else "" lives inside `if base_url:` — base_url is unconditionally truthy there, so the else branch was dead code. No behavior change. Tests still 7/7 green. Co-Authored-By: Claude Opus 4.7 (1M context) --- adapter.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/adapter.py b/adapter.py index 0a3014d..8ab37d3 100644 --- a/adapter.py +++ b/adapter.py @@ -237,7 +237,6 @@ class ClaudeCodeAdapter(BaseAdapter): # "sonnet" fallback — that's correct behavior, no error. base_url = os.environ.get("ANTHROPIC_BASE_URL", "").strip() if base_url and not explicit_model: - from urllib.parse import urlparse host = urlparse(base_url).hostname or "" if host and host != "api.anthropic.com": raise ValueError( @@ -257,12 +256,10 @@ class ClaudeCodeAdapter(BaseAdapter): # adapter sent X to Y" without having to dig into the SDK # subprocess. Cheap diagnostic, no runtime cost. if base_url: - from urllib.parse import urlparse logger.info( - "claude-code: model=%s base_url_host=%s%s", + "claude-code: model=%s base_url_host=%s (custom upstream)", model, urlparse(base_url).hostname or "", - " (custom upstream)" if base_url else "", ) else: logger.info("claude-code: model=%s base_url=anthropic-default", model)