Skip to content

Commit

Permalink
Fix python 3.9 builds.
Browse files Browse the repository at this point in the history
The `|` syntax for union types (PEP 604) was introduced in Python 3.10.

PiperOrigin-RevId: 560222348
  • Loading branch information
lingvo-bot authored and copybara-github committed Aug 25, 2023
1 parent e5adc4c commit 09c7f07
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lingvo/core/hyperparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__

Expand Down Expand Up @@ -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
):
Expand Down

0 comments on commit 09c7f07

Please sign in to comment.