Skip to content

Commit 88f759a

Browse files
seanzhougooglecopybara-github
authored andcommitted
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
1 parent e295feb commit 88f759a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/google/adk/tools/bigquery/query_tool.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import functools
1818
import json
19+
import sys
20+
import textwrap
1921
import types
2022
from typing import Callable
2123

@@ -494,8 +496,17 @@ def get_execute_sql(config: BigQueryToolConfig) -> Callable[..., dict]:
494496

495497
# Now, set the new docstring
496498
if config.write_mode == WriteMode.PROTECTED:
497-
execute_sql_wrapper.__doc__ += _execute_sql_protecetd_write_examples
499+
examples = _execute_sql_protecetd_write_examples
498500
else:
499-
execute_sql_wrapper.__doc__ += _execute_sql_write_examples
501+
examples = _execute_sql_write_examples
502+
503+
# Handle Python 3.13+ inspect.cleandoc behavior change
504+
# Python 3.13 changed inspect.cleandoc from lstrip() to lstrip(' '), making it
505+
# more conservative. The appended examples have inconsistent indentation that
506+
# Python 3.11/3.12's aggressive cleandoc would fix, but 3.13+ needs help.
507+
if sys.version_info >= (3, 13):
508+
examples = textwrap.dedent(examples)
509+
510+
execute_sql_wrapper.__doc__ += examples
500511

501512
return execute_sql_wrapper

0 commit comments

Comments
 (0)