From 88f759a941c95beef0571f36f8e7a34f27971ba8 Mon Sep 17 00:00:00 2001 From: "Xiang (Sean) Zhou" Date: Mon, 11 Aug 2025 21:25:47 -0700 Subject: [PATCH] fix: docstring concatenation in 3.13 The issue was caused by a breaking change in Python 3.13's inspect.cleandoc() function that made it more conservative about whitespace handling: Root Cause: - Python 3.12-: inspect.cleandoc() used line.lstrip() - strips all whitespace (spaces, tabs, etc.) - Python 3.13+: inspect.cleandoc() uses line.lstrip(' ') - strips only space characters PiperOrigin-RevId: 793921360 --- src/google/adk/tools/bigquery/query_tool.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/google/adk/tools/bigquery/query_tool.py b/src/google/adk/tools/bigquery/query_tool.py index c44ca67b..f989a9f7 100644 --- a/src/google/adk/tools/bigquery/query_tool.py +++ b/src/google/adk/tools/bigquery/query_tool.py @@ -16,6 +16,8 @@ from __future__ import annotations import functools import json +import sys +import textwrap import types from typing import Callable @@ -494,8 +496,17 @@ def get_execute_sql(config: BigQueryToolConfig) -> Callable[..., dict]: # Now, set the new docstring if config.write_mode == WriteMode.PROTECTED: - execute_sql_wrapper.__doc__ += _execute_sql_protecetd_write_examples + examples = _execute_sql_protecetd_write_examples else: - execute_sql_wrapper.__doc__ += _execute_sql_write_examples + examples = _execute_sql_write_examples + + # Handle Python 3.13+ inspect.cleandoc behavior change + # Python 3.13 changed inspect.cleandoc from lstrip() to lstrip(' '), making it + # more conservative. The appended examples have inconsistent indentation that + # Python 3.11/3.12's aggressive cleandoc would fix, but 3.13+ needs help. + if sys.version_info >= (3, 13): + examples = textwrap.dedent(examples) + + execute_sql_wrapper.__doc__ += examples return execute_sql_wrapper