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
This commit is contained in:
Xiang (Sean) Zhou
2025-08-11 21:26:25 -07:00
committed by Copybara-Service
parent e295feb4c6
commit 88f759a941
+13 -2
View File
@@ -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