From c3067cb52138d991cd4d448f72a2895a61adb26d Mon Sep 17 00:00:00 2001 From: Dan Moldovan Date: Thu, 11 Jun 2020 13:04:55 -0700 Subject: [PATCH] Fix bug that causes parameterized type annotations to lose their arguments. This prevents errors in Python 3.5 when combined with #40132. PiperOrigin-RevId: 315961338 Change-Id: I01604b87bcee4b8e687055f727b8bdfc5da53376 --- tensorflow/python/util/tf_should_use.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tensorflow/python/util/tf_should_use.py b/tensorflow/python/util/tf_should_use.py index 9ba4b7520e5..1671b078fa3 100644 --- a/tensorflow/python/util/tf_should_use.py +++ b/tensorflow/python/util/tf_should_use.py @@ -152,7 +152,9 @@ def _get_wrapper(x, tf_should_use_helper): return memoized(x, tf_should_use_helper) tx = copy.deepcopy(type_x) - copy_tx = type(tx.__name__, tx.__bases__, dict(tx.__dict__)) + # Prefer using __orig_bases__, which preserve generic type arguments. + bases = getattr(tx, '__orig_bases__', tx.__bases__) + copy_tx = type(tx.__name__, bases, dict(tx.__dict__)) copy_tx.__init__ = _new__init__ copy_tx.__getattribute__ = _new__getattribute__ copy_tx.mark_used = _new_mark_used