From 95de5353e571f5e70091c4df2996cd46927e3032 Mon Sep 17 00:00:00 2001 From: Ezekiel Calubaquib Date: Wed, 18 Jun 2025 10:47:23 -0700 Subject: [PATCH] Fix Python 3.13 wheel test and requirements PiperOrigin-RevId: 772980569 --- requirements_lock_3_13.txt | 6 ++--- .../python/autograph/pyct/parser_test.py | 7 +++++- tensorflow/python/ops/distributions/util.py | 13 +++++++--- tensorflow/python/util/dispatch.py | 24 +++++++++++-------- tensorflow/python/util/dispatch_test.py | 21 ++++++++-------- .../python/util/traceback_utils_test.py | 11 +++++++-- 6 files changed, 53 insertions(+), 29 deletions(-) diff --git a/requirements_lock_3_13.txt b/requirements_lock_3_13.txt index bffeb2639f3..79db8c0f98a 100644 --- a/requirements_lock_3_13.txt +++ b/requirements_lock_3_13.txt @@ -4,9 +4,9 @@ # # bazel run //ci/official/requirements_updater:requirements.update # -absl-py==2.2.1 \ - --hash=sha256:4c7bc50d42d021c12d4f31b7001167925e0bd71ade853069f64af410f5565ff9 \ - --hash=sha256:ca8209abd5005ae6e700ef36e2edc84ad5338678f95625a3f15275410a89ffbc +absl-py==2.3.0 \ + --hash=sha256:d96fda5c884f1b22178852f30ffa85766d50b99e00775ea626c23304f582fc4f \ + --hash=sha256:9824a48b654a306168f63e0d97714665f8490b8d89ec7bf2efc24bf67cf579b3 # via # dm-tree # keras-nightly diff --git a/tensorflow/python/autograph/pyct/parser_test.py b/tensorflow/python/autograph/pyct/parser_test.py index 810c1d7bf74..5ed2fb9357a 100644 --- a/tensorflow/python/autograph/pyct/parser_test.py +++ b/tensorflow/python/autograph/pyct/parser_test.py @@ -15,6 +15,7 @@ """Tests for parser module.""" import re +import sys import textwrap import gast @@ -292,7 +293,11 @@ string""") """ f = self._eval_code(parser.dedent_block(code), 'f') - self.assertEqual(f.__doc__, '\n Docstring.\n ') + if sys.version_info >= (3, 13): + self.assertEqual(f.__doc__.strip(), 'Docstring.') + else: + self.assertEqual(f.__doc__, '\n Docstring.\n ') + self.assertEqual(f(), '\n 1\n 2\n 3') def test_dedent_block_multiline_expression(self): diff --git a/tensorflow/python/ops/distributions/util.py b/tensorflow/python/ops/distributions/util.py index 62f91b7003a..6e98addc9e2 100644 --- a/tensorflow/python/ops/distributions/util.py +++ b/tensorflow/python/ops/distributions/util.py @@ -16,6 +16,7 @@ import functools import hashlib +import sys import numpy as np @@ -1373,15 +1374,21 @@ def parent_frame_arguments(): # Remove the *varargs, and flatten the **kwargs. Both are # nested lists. - local_vars.pop(variable_arg_name, {}) - keyword_args = local_vars.pop(keyword_arg_name, {}) + if sys.version_info >= (3, 13): + keyword_args = local_vars.get(keyword_arg_name, {}) + else: + local_vars.pop(variable_arg_name, {}) + keyword_args = local_vars.pop(keyword_arg_name, {}) final_args = {} # Copy over arguments and their values. In general, local_vars # may contain more than just the arguments, since this method # can be called anywhere in a function. for arg_name in arg_names: - final_args[arg_name] = local_vars.pop(arg_name) + if sys.version_info >= (3, 13): + final_args[arg_name] = local_vars[arg_name] + else: + final_args[arg_name] = local_vars.pop(arg_name) final_args.update(keyword_args) return final_args diff --git a/tensorflow/python/util/dispatch.py b/tensorflow/python/util/dispatch.py index ff1fa45ba2a..528aa595096 100644 --- a/tensorflow/python/util/dispatch.py +++ b/tensorflow/python/util/dispatch.py @@ -1155,27 +1155,31 @@ def update_docstrings_with_api_lists(): `dispatch_for_binary_elementwise_apis`, by replacing the string '<>' with a list of APIs that have been registered for that decorator. """ - _update_docstring_with_api_list(dispatch_for_unary_elementwise_apis, - _UNARY_ELEMENTWISE_APIS) - _update_docstring_with_api_list(dispatch_for_binary_elementwise_apis, - _BINARY_ELEMENTWISE_APIS) - _update_docstring_with_api_list(dispatch_for_binary_elementwise_assert_apis, - _BINARY_ELEMENTWISE_ASSERT_APIS) - _update_docstring_with_api_list(dispatch_for_api, - _TYPE_BASED_DISPATCH_SIGNATURES) + _update_docstring_with_api_list( + dispatch_for_unary_elementwise_apis, _UNARY_ELEMENTWISE_APIS) + _update_docstring_with_api_list( + dispatch_for_binary_elementwise_apis, _BINARY_ELEMENTWISE_APIS) + _update_docstring_with_api_list( + dispatch_for_binary_elementwise_assert_apis, + _BINARY_ELEMENTWISE_ASSERT_APIS) + _update_docstring_with_api_list( + dispatch_for_api, _TYPE_BASED_DISPATCH_SIGNATURES) def _update_docstring_with_api_list(target, api_list): """Replaces `<>` in target.__doc__ with the given list of APIs.""" lines = [] for func in api_list: + if isinstance(func, dict): + func = list(func.keys())[0] name = tf_export_lib.get_canonical_name_for_symbol( - func, add_prefix_to_v1_names=True) + func, add_prefix_to_v1_names=True + ) if name is not None: params = tf_inspect.signature(func).parameters.keys() lines.append(f" * `tf.{name}({', '.join(params)})`") lines.sort() - target.__doc__ = target.__doc__.replace(" <>", "\n".join(lines)) + target.__doc__ = target.__doc__.replace("<>", "\n".join(lines)) ################################################################################ diff --git a/tensorflow/python/util/dispatch_test.py b/tensorflow/python/util/dispatch_test.py index 4576ba17d53..74fb1da143b 100644 --- a/tensorflow/python/util/dispatch_test.py +++ b/tensorflow/python/util/dispatch_test.py @@ -1143,21 +1143,22 @@ class DispatchV2Test(test_util.TensorFlowTestCase): dispatch.update_docstrings_with_api_lists() self.assertRegex( dispatch.dispatch_for_api.__doc__, - r"(?s) The TensorFlow APIs that may be overridden " - r"by `@dispatch_for_api` are:\n\n.*" - r" \* `tf\.concat\(values, axis, name\)`\n.*" - r" \* `tf\.math\.add\(x, y, name\)`\n.*") + r"(?s)The TensorFlow APIs that may be overridden " + r"by `@dispatch_for_api` are:.*" + r"\* `tf\.concat\(values, axis, name\)`.*" + r"\* `tf\.math\.add\(x, y, name\)`.*") self.assertRegex( dispatch.dispatch_for_unary_elementwise_apis.__doc__, - r"(?s) The unary elementwise APIs are:\n\n.*" - r" \* `tf\.math\.abs\(x, name\)`\n.*" - r" \* `tf\.math\.cos\(x, name\)`\n.*") + r"(?s)The unary elementwise APIs are:.*" + r"\* `tf\.math\.abs\(x, name\)`.*" + r"\* `tf\.math\.cos\(x, name\)`.*") self.assertRegex( dispatch.dispatch_for_binary_elementwise_apis.__doc__, - r"(?s) The binary elementwise APIs are:\n\n.*" - r" \* `tf\.math\.add\(x, y, name\)`\n.*" - r" \* `tf\.math\.multiply\(x, y, name\)`\n.*") + r"(?s)The binary elementwise APIs are:.*" + r"\* `tf\.math\.add\(x, y, name\)`.*" + r"\* `tf\.math\.multiply\(x, y, name\)`.*") if __name__ == "__main__": googletest.main() + diff --git a/tensorflow/python/util/traceback_utils_test.py b/tensorflow/python/util/traceback_utils_test.py index 741f5b66f53..0eda1b7d369 100644 --- a/tensorflow/python/util/traceback_utils_test.py +++ b/tensorflow/python/util/traceback_utils_test.py @@ -14,6 +14,7 @@ # ============================================================================== """Tests for traceback_utils.""" +import sys import traceback from tensorflow.python.eager import def_function @@ -46,7 +47,10 @@ class TracebackUtilsTest(test.TestCase): self.assertGreater(trace_line_count, 0) if filtering_enabled: - self.assertLess(trace_line_count, count) + if sys.version_info >= (3, 13): + self.assertLessEqual(trace_line_count, count) + else: + self.assertLess(trace_line_count, count) else: self.assertGreater(trace_line_count, count) @@ -96,7 +100,10 @@ class TracebackUtilsTest(test.TestCase): def fn(): wrapped_fn([0, 1]) - self.assert_trace_line_count(fn, count=15, filtering_enabled=True) + if sys.version_info >= (3, 13): + self.assert_trace_line_count(fn, count=16, filtering_enabled=True) + else: + self.assert_trace_line_count(fn, count=15, filtering_enabled=True) self.assert_trace_line_count(fn, count=25, filtering_enabled=False) def test_variable_constructor(self):