@@ -68,7 +68,9 @@ def _module_attr(module, attr):
6868# Define TensorFlow module types.
6969_tf_tensor = ModuleType ("tensorflow" , "Tensor" )
7070_tf_indexedslices = ModuleType ("tensorflow" , "IndexedSlices" )
71- _tf_kerastensor = ModuleType ("keras" , "KerasTensor" )
71+ # On Python 3.9 and higher, we also need to support `keras.KerasTensor`.
72+ if sys .version_info >= (3 , 9 ):
73+ _tf_kerastensor = ModuleType ("keras" , "KerasTensor" )
7274_tf_variable = ModuleType ("tensorflow" , "Variable" )
7375_tf_dtype = ModuleType ("tensorflow" , "DType" )
7476_tf_randomstate = ModuleType ("tensorflow" , "random.Generator" )
@@ -107,7 +109,10 @@ def _module_attr(module, attr):
107109NPNumeric = set_union_alias (NPNumeric , "B.NPNumeric" )
108110AGNumeric = Union [_ag_tensor ]
109111AGNumeric = set_union_alias (AGNumeric , "B.AGNumeric" )
110- TFNumeric = Union [_tf_tensor , _tf_variable , _tf_indexedslices , _tf_kerastensor ]
112+ if sys .version_info >= (3 , 9 ):
113+ TFNumeric = Union [_tf_tensor , _tf_variable , _tf_indexedslices , _tf_kerastensor ]
114+ else :
115+ TFNumeric = Union [_tf_tensor , _tf_variable , _tf_indexedslices ]
111116TFNumeric = set_union_alias (TFNumeric , "B.TFNumeric" )
112117TorchNumeric = Union [_torch_tensor ]
113118TorchNumeric = set_union_alias (TorchNumeric , "B.TorchNumeric" )
0 commit comments