Skip to content

Commit 96f370f

Browse files
committed
Fix Python 3.8
1 parent f16beb7 commit 96f370f

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

lab/types.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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):
107109
NPNumeric = set_union_alias(NPNumeric, "B.NPNumeric")
108110
AGNumeric = Union[_ag_tensor]
109111
AGNumeric = 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]
111116
TFNumeric = set_union_alias(TFNumeric, "B.TFNumeric")
112117
TorchNumeric = Union[_torch_tensor]
113118
TorchNumeric = set_union_alias(TorchNumeric, "B.TorchNumeric")

0 commit comments

Comments
 (0)