From 09c7f0707c321ede852a530f40430bb7b7e9ad85 Mon Sep 17 00:00:00 2001 From: Lingvo Maintenance Date: Fri, 25 Aug 2023 16:21:51 -0700 Subject: [PATCH] Fix python 3.9 builds. The `|` syntax for union types (PEP 604) was introduced in Python 3.10. PiperOrigin-RevId: 560222348 --- lingvo/core/hyperparams.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lingvo/core/hyperparams.py b/lingvo/core/hyperparams.py index 49e9e9316..00ea8914d 100644 --- a/lingvo/core/hyperparams.py +++ b/lingvo/core/hyperparams.py @@ -564,7 +564,7 @@ def _ToParamValue(key: str, val: Any) -> hyperparams_pb2.HyperparamValue: param_pb.dict_val.SetInParent() for k, v in val.items(): param_pb.dict_val.items[k].CopyFrom(_ToParamValue(f'{key}[{k}]', v)) - elif isinstance(val, type | types.FunctionType): + elif isinstance(val, type) or isinstance(val, types.FunctionType): param_pb.type_val = inspect.getmodule(val).__name__ + '/' + val.__name__ elif isinstance(val, tf.DType): param_pb.dtype_val = val.name @@ -825,7 +825,7 @@ def GetRepr(val: Any): proto_str = text_format.MessageToString(val, as_one_line=True) return 'proto/%s/%s/%s' % (inspect.getmodule(val).__name__, type(val).__name__, proto_str) - if isinstance(val, type | types.FunctionType): + if isinstance(val, type) or isinstance(val, types.FunctionType): return 'type/' + inspect.getmodule(val).__name__ + '/' + val.__name__ return type(val).__name__ @@ -980,7 +980,8 @@ def _ValueFromText(key: str, old_val: Any, val: str) -> Any: (val_type, cls)) return type(old_val)[name] elif ( - isinstance(old_val, type | types.FunctionType) + isinstance(old_val, type) + or isinstance(old_val, types.FunctionType) or isinstance(old_val, message.Message) or old_val is None ):